v2.1.39
Lits is a lexically scoped pure functional language with algebraic notation. It combines the power of functional programming with an intuitive, readable syntax.
Features
Pure functional language
- Variables cannot be changed, ensuring predictable behavior and easier reasoning about code
JavaScript interoperability
- JavaScript values and functions can easily be exposed in Lits
Algebraic notation
- All operators can be used as functions, and functions that take two parameters can be used as operators
Algebraic notation
- All operators can be used as functions, and functions that take two parameters can be used as operators
Clojure-inspired functions
- Most core functions are inspired by Clojure
Comprehensive standard library
- Rich set of functions for collections, math, strings, and more
Structural equality
- Objects are compared by value, not by reference
Destructuring
- Extract values from complex data structures with ease
Happy coding!
Examples
Simple Lits program
A super simple example.
Play!
Collection accessors
Syntactic sugar for accessing object, array and string elements.
Play!
// Access object properies with .
// Access string and array elements with []
let data = {
numbers: [1, 2, 3],
chars: ["a", "b", "c"],
string: "Albert"
};
write!(data.numbers[0]);
write!(data.chars[2]);
write!(data.string[0]);
write!({a: 1, b: 2, c: 3}.b);
write!("Albert"[3]);
write!([1, 2, 3][2]);
Using context
Simple example using a context.
Play!
A game
Text based adventure game.
Play!
// Functional Text Adventure Game in Lits
// Define locations
let locations = {
forest: {
description: "You are in a dense forest. Light filters through the leaves above.",
exits: { north: "cave", east: "river", south: "meadow" }
},
cave: {
description: "You stand in a dark cave. Water drips from stalactites overhead.",
exits: { south: "forest", east: "tunnel" },
items: ["torch"]
},
river: {
description: "A swift river flows from the mountains. The water is crystal clear.",
exits: { west: "forest", north: "waterfall" },
items: ["fishing rod"]
},
meadow: {
description: "A peaceful meadow stretches before you, filled with wildflowers.",
exits: { north: "forest", east: "cottage" },
items: ["flowers"]
},
waterfall: {
description: "A magnificent waterfall cascades down from high cliffs.",
exits: { south: "river" },
items: ["shiny stone"]
},
tunnel: {
description: "A narrow tunnel leads deeper into the mountain.",
exits: { west: "cave", east: "treasure room" }
},
"treasure room": {
description: "A small chamber glittering with treasure!",
exits: { west: "tunnel" },
items: ["gold key", "ancient map", "jeweled crown"]
},
cottage: {
description: "A cozy cottage with a smoking chimney stands here.",
exits: { west: "meadow" },
items: ["bread"]
}
};
// Define game state
let initial-state = {
current-location: "forest",
inventory: [],
visited: {},
game-over: false,
moves: 0,
light-source: false
};
// Helper functions
let has-item? = (state, item) -> {
contains?(state.inventory, item);
};
let location-has-item? = (location, item) -> {
contains?(get(location, "items", []), item);
};
let describe-location = (state) -> {
let location = get(locations, state.current-location);
let description = location.description;
// Add visited status
let visited-status = if get(state.visited, state.current-location, 0) > 1 then
"You've been here before."
else
"This is your first time here."
end;
// Check if location has items
let items-desc = if !(empty?(get(location, "items", []))) then
"You see: " ++ join(location.items, ", ")
else
""
end;
// Describe exits
let exits = keys(location.exits) join ", ";
let exits-desc = "Exits: " ++ exits;
// Join all descriptions
filter([description, visited-status, items-desc, exits-desc], -> !(empty?($))) join "\n"
};
let get-location-items = (state) -> {
let location = get(locations, state.current-location);
get(location, "items", [])
};
// Game actions
let move = (state, direction) -> {
let location = get(locations, state.current-location);
let exits = get(location, "exits", {});
// Check if direction is valid
if contains?(exits, direction) then
let new-location = get(exits, direction);
let is-dark = new-location == "tunnel" || new-location == "treasure room";
// Check if player has light source for dark areas
if is-dark && !(state.light-source) then
[state, "It's too dark to go that way without a light source."]
else
let new-visited = assoc(
state.visited,
new-location,
inc(state.visited["new-location"] ?? 0)
);
let new-state = assoc(
assoc(
assoc(state, "current-location", new-location),
"visited",
new-visited
),
"moves",
state.moves + 1
);
[new-state, "You move " ++ direction ++ " to the " ++ new-location ++ "."]
end
else
[state, "You can't go that way."]
end
};
let take! = (state, item) -> {
let items = get-location-items(state);
if contains?(items, item) then
let location = get(locations, state.current-location);
let new-location-items = filter(items, -> $ ≠ item);
let new-inventory = push(state.inventory, item);
// Update game state
let new-locations = assoc(
locations,
state.current-location,
assoc(location, "items", new-location-items)
);
// Special case for torch
let has-light = item == "torch" || state.light-source;
// Update locations and state
let locations = new-locations;
let new-state = assoc(
assoc(
assoc(state, "inventory", new-inventory),
"light-source", has-light
),
"moves",
state.moves + 1
);
[new-state, "You take the " ++ item ++ "."]
else
[state, "There is no " ++ item ++ " here."]
end
};
let drop! = (state, item) -> {
if has-item?(state, item) then
let location = get(locations, state.current-location);
let location-items = get(location, "items", []);
let new-location-items = push(location-items, item);
let new-inventory = filter(-> $ ≠ item, state.inventory);
// Special case for torch
let still-has-light = !(item == "torch") || contains?(new-inventory, "torch");
// Update locations and state
let new-location = assoc(location, "items", new-location-items);
let locations = assoc(locations, state.current-location, new-location);
let new-state = assoc(
assoc(
assoc(
state, "inventory", new-inventory),
"light-source",
still-has-light
),
"moves",
state.moves + 1
);
[new-state, "You drop the " ++ item ++ "."]
else
[state, "You don't have a " ++ item ++ " in your inventory."]
end
};
let inventory = (state) -> {
if empty?(state.inventory) then
[state, "Your inventory is empty."]
else
[state, "Inventory: " ++ join(state.inventory, ", ")]
end
};
let use = (state, item) -> {
switch item
case "fishing rod" then
if state.current-location == "river" then
[assoc(state, "moves", state.moves + 1), "You catch a small fish, but it slips away."]
else
[state, "There's no place to use a fishing rod here."]
end
case "torch" then
if has-item?(state, item) then
[
assoc(assoc(state, "light-source", true), "moves", state.moves + 1),
"The torch illuminates the area with a warm glow."
]
else
[state, "You don't have a torch."]
end
case "gold key" then
if has-item?(state, item) && state.current-location == "treasure room" then
[
assoc(
assoc(state, "game-over", true),
"moves",
state.moves + 1
),
"You use the gold key to unlock a secret compartment, revealing a fabulous diamond! You win!"
]
else
[state, "The key doesn't fit anything here."]
end
case "bread" then
if has-item?(state, item) then
let new-inventory = filter(state.inventory, -> $ ≠ item);
[
assoc(
assoc(state, "inventory", new-inventory),
"moves",
state.moves + 1
),
"You eat the bread. It's delicious and nourishing."
]
else
[state, "You don't have any bread."]
end
case "shiny stone" then
if has-item?(state, item) then
[
assoc(state, "moves", state.moves + 1),
"The stone glows with a faint blue light. It seems magical but you're not sure how to use it yet."
]
else
[state, "You don't have a shiny stone."]
end
case "flowers" then
if has-item?(state, item) then
[
assoc(state, "moves", state.moves + 1),
"You smell the flowers. They have a sweet, calming fragrance."
]
else
[state, "You don't have any flowers."]
end
case "ancient map" then
if has-item?(state, item) then
[
assoc(state, "moves", state.moves + 1),
"The map shows the layout of the area. All locations are now marked as visited."
]
else
[state, "You don't have a map."]
end
case "jeweled crown" then
if has-item?(state, item) then
[
assoc(state, "moves", state.moves + 1),
"You place the crown on your head. You feel very regal."
]
else
[state, "You don't have a crown."]
end
end ?? [state, "You can't use that."]
};
// Command parser
let parse-command = (state, input) -> {
let tokens = lower-case(input) split " ";
let command = first(tokens);
let args = rest(tokens) join " ";
let result = switch command
case "go" then
move(state, args)
case "north" then
move(state, "north")
case "south" then
move(state, "south")
case "east" then
move(state, "east")
case "west" then
move(state, "west")
case "take" then
take!(state, args)
case "drop" then
drop!(state, args)
case "inventory" then
inventory(state)
case "i" then
inventory(state)
case "look" then
[assoc(state, "moves", state.moves + 1), describe-location(state)]
case "use" then
use(state, args)
case "help" then
[state, "Commands then go [direction], north, south, east, west, take [item], drop [item], inventory, look, use [item], help, quit"]
case "quit" then
[assoc(state, "game-over", true), "Thanks for playing!"]
end ?? [state, "I don't understand that command. Type 'help' for a list of commands."];
result
};
// Game loop
let game-loop = (state) -> {
alert!(describe-location(state) ++ "\nWhat do you do? ");
let input = read-line!();
let command_result = parse-command(state, input);
let new-state = first(command_result);
let message = second(command_result);
alert!("\n" ++ message ++ "\n");
if new-state.game-over then
alert!("\nGame over! You made " ++ str(new-state.moves) ++ " moves.");
new-state
else
game-loop(new-state)
end
};
// Start game
let start-game = () -> {
alert!("=== Lits Adventure Game ===\n" ++ "Type 'help' for a list of commands.\n\n");
game-loop(initial-state)
};
// Call the function to start the game
start-game()
Determinant
Determinant function for square matrices.
Play!
// Determinant function for square matrices
let determinant = (matrix) -> {
// Check if input is an array
unless array?(matrix) then
throw("Input must be an array");
end;
// Check if matrix is empty
if empty?(matrix) then
throw("Matrix cannot be empty");
end;
let rows = count(matrix);
// Get first row to check column count
let firstRow = first(matrix);
// Check if first row is an array
unless array?(firstRow) then
throw("Input must be a 2D array");
end;
let cols = count(firstRow);
// Ensure matrix is square
if rows ≠ cols then
throw("Matrix must be square");
end;
// Base case: 1x1 matrix
if rows == 1 then
matrix[0][0];
else
// Base case: 2x2 matrix
if rows == 2 then
let a = matrix[0][0];
let b = matrix[0][1];
let c = matrix[1][0];
let d = matrix[1][1];
a * d - b * c;
else
// For larger matrices, use cofactor expansion along first row
// Use reduce to calculate the determinant without mutating variables
reduce(
range(cols),
(acc, j) -> {
let minor = getMinor(matrix, 0, j);
let cofactor = determinant(minor);
let signFactor = even?(j) ? 1 : -1;
let term = signFactor * matrix[0][j] * cofactor;
acc + term;
},
0,
);
end
end
};
// Helper function to get minor (submatrix) by removing specific row and column
let getMinor = (matrix, rowToRemove, colToRemove) -> {
// Use map with filter to create the new matrix without mutating
map(
range(count(matrix)),
i -> {
if i == rowToRemove then
null; // This will be filtered out
else
let row = get(matrix, i);
// Filter out the column to remove
map(
range(count(row)),
j -> {
if j == colToRemove then
null; // This will be filtered out
else
get(row, j)
end
}
) filter (item -> item ≠ null);
end
}
) filter (row -> row ≠ null);
};
// 4x4 invertible matrix
let matrix4x4 = [
[4, 3, 2, 2],
[0, 1, -3, 3],
[0, -1, 3, 3],
[0, 3, 1, 1]
];
determinant(matrix4x4);
Matrix multiplication
Matrix multiplication with correct syntax.
Play!
// Matrix multiplication with correct syntax
let matrixMultiply = (matrixA, matrixB) -> {
// Check if inputs are arrays
unless array?(matrixA) then throw("First input must be an array") end;
unless array?(matrixB) then throw("Second input must be an array") end;
// Check if matrices are not empty
if empty?(matrixA) || empty?(matrixB) then throw("Matrices cannot be empty") end;
// Check if matrices are 2D arrays
unless array?(first(matrixA)) then throw("First input must be a 2D array") end;
unless array?(first(matrixB)) then throw("Second input must be a 2D array") end;
// Get dimensions
let rowsA = count(matrixA);
let colsA = count(first(matrixA));
let rowsB = count(matrixB);
let colsB = count(first(matrixB));
// Check if all rows have consistent length
unless every?(matrixA, row -> array?(row) && count(row) == colsA) then
throw("First matrix has inconsistent row lengths")
end;
unless every?(matrixB, row -> array?(row) && count(row) == colsB) then
throw("Second matrix has inconsistent row lengths")
end;
// Check if matrices can be multiplied
unless colsA == rowsB then
throw("Matrix dimensions mismatch: first matrix columns must equal second matrix rows");
end;
// Create a row of the result matrix
let createRow = (rowIndex) -> {
for (j in range(colsB)) -> {
reduce(
range(colsA),
(sum, k) -> {
let aValue = matrixA[rowIndex][k];
let bValue = matrixB[k][j];
sum + (aValue * bValue);
},
0
)
}
};
// Create the result matrix row by row
for (i in range(rowsA)) -> createRow(i);
};
let matrixA = [
[1, 2, 3],
[4, 5, 6]
];
let matrixB = [
[7, 8],
[9, 10],
[11, 12]
];
matrixMultiply(matrixA, matrixB);
Phone number formatter
Pretty prints a US phone number.
Play!
let formatPhoneNumber = (data) -> {
if string?(data) then
let phoneNumber = data[0] == "+" ? data slice 2 : data;
let length = count(phoneNumber);
cond
case length > 6 then
"(" ++ slice(phoneNumber, 0, 3) ++ ") " ++ slice(phoneNumber, 3, 6) ++ "-" ++ slice(phoneNumber, 6)
case length > 3 then
"(" ++ slice(phoneNumber, 0, 3) ++ ") " ++ slice(phoneNumber, 3)
case length > 0 then
"(" ++ slice(phoneNumber, 0)
end ?? ""
else
""
end
};
write!(formatPhoneNumber);
write!(formatPhoneNumber(123234));
write!(formatPhoneNumber("123234"));
write!(formatPhoneNumber("1232343456"));
write!(formatPhoneNumber("+11232343456789"));
write!(formatPhoneNumber("+11232343456"));
Factorial
A recursive implementation of the factorial function.
Play!
let factorial = (x) -> {
if x == 1 then
1
else
x * self(x - 1)
end
};
factorial(5)
Sort
Sort an array of numbers.
Play!
let l = [7, 39, 45, 0, 23, 1, 50, 100, 12, -5];
let numberComparer = (a, b) -> {
cond
case a < b then -1
case a > b then 1
end ?? 0
};
sort(l, numberComparer)
Is ISO date string
Check if string is formatted as an ISO date string.
Play!
let isoDateString? = (data) -> {
let m = data match #"^(\d{4})-(\d{2})-(\d{2})$";
if m then
let [year, month, day] = slice(m, 1) map number;
let leapYear = zero?(year mod 4) && (!zero?(year mod 100) || zero?(year mod 400));
let invalid =
(year < 1900 || year > 2100)
|| (month < 1 || month > 12)
|| (day < 1 || day > 31)
|| day > 30 && (month == 4 || month == 6 || month == 9 || month == 11)
|| month == 2 && (leapYear && day > 29 || !leapYear && day > 28);
!(invalid)
else
false
end
};
write!(isoDateString?("1978-12-21"));
write!(isoDateString?("197-12-21"));
label-from-value
Find label to corresponding value in array of { label, value }-objects.
Play!
let label-from-value = (items, value) -> {
let entry = items some (-> value == $["value"]);
if entry == null then
null
else
entry["label"]
end
};
let items = [
{ label: "Name", value: "name" },
{ label: "Age", value: "age" }
];
label-from-value(items, "name");
labels-from-values
Find labels to corresponding values in array of { label, value }-objects.
Play!
let labels-from-values = ($array, $values) -> {
for (
value in $values
let label = {
let entry = $array some -> value == $["value"];
if entry == null then
value
else
entry["label"]
end
}
) -> label
};
let arr = [
{ label: "Name", value: "name" },
{ label: "Age", value: "age" },
{ label: "Email", value: "email" },
];
labels-from-values(arr, ["name", "age"])
Namespaces
Lits organizes additional functionality into namespaces.
Unlike core functions which are always available, namespace functions must be
imported before use.
To use a namespace, use the import special expression
to load the namespace, then call its functions using dot notation:
; Import the Vector namespace
let vec = import("Vector")
; Use vec.sum, vec.mean, etc.
vec.sum([1, 2, 3, 4, 5])
Available namespaces: Vector, Linear-Algebra, Matrix, Grid, Number-Theory, Random, undefined
Vector
(import "Vector")
Statistical and mathematical operations on vectors (arrays of numbers). Includes functions for sum, mean, median, standard deviation, and more.
let vec = import("Vector"); vec.sum([1, 2, 3, 4, 5])
let vec = import("Vector"); vec.mean([1, 2, 3, 4, 5])
let vec = import("Vector"); vec.stdev([1, 2, 3, 4, 5])
Linear Algebra
(import "Linear-Algebra")
Linear algebra operations including dot product, cross product, and vector norms.
let lin = import("Linear-Algebra"); lin.dot([1, 2, 3], [4, 5, 6])
let lin = import("Linear-Algebra"); lin.cross([1, 0, 0], [0, 1, 0])
let lin = import("Linear-Algebra"); lin.norm([3, 4])
Matrix
(import "Matrix")
Matrix operations including creation, manipulation, and mathematical operations like determinant, transpose, and multiplication.
let mat = import("Matrix"); mat.identity(3)
let mat = import("Matrix"); mat.transpose([[1, 2], [3, 4]])
let mat = import("Matrix"); mat.det([[1, 2], [3, 4]])
Grid
(import "Grid")
Grid (2D array) operations for creating and manipulating two-dimensional data structures.
let grid = import("Grid"); grid.create(3, 3, 0)
let grid = import("Grid"); grid.get(grid.create(3, 3, :x), 1, 1)
Number Theory
(import "Number-Theory")
Number theory functions including prime numbers, factorials, fibonacci sequences, and more.
let nt = import("Number-Theory"); nt.prime?(17)
let nt = import("Number-Theory"); nt.fibonacci-seq(10)
let nt = import("Number-Theory"); nt.factorial(5)
Random
(import "Random")
Random number generation and related functions.
let rand = import("Random"); rand.random!()
let rand = import("Random"); rand.random-int!(1, 100)
let rand = import("Random"); rand.shuffle!([1, 2, 3, 4, 5])
Asseert
(import "Assert")
Assertion functions for validating conditions and throwing errors.
let { assert } = import("Assert");
try assert(0, "Expected a positive value") catch (e) e.message end
Description
Shifts a arithmetically left by b bit positions.
Description
Shifts a arithmetically right by b bit positions.
Description
Shifts a arithmetically right by b bit positions without sign extension.
Description
Returns bitwise not of a.
Description
Returns bitwise and of all arguments.
Examples
>
&(0b0011, 0b0110, 0b1001)
0
Description
Returns bitwise and with complement.
Examples
>
0b0011 bit-and-not 0b0110
1
>
bit-and-not(0b0011, 0b0110)
1
>
bit-and-not(0b0011, 0b0110, 0b1001)
0
Description
Returns bitwise or of all arguments.
Examples
>
|(0b1000, 0b0100, 0b0010)
14
Description
Returns bitwise xor of all arguments.
Examples
>
xor(0b11110000, 0b00111100, 0b10101010)
102
Description
Flips bit number b.
Description
Clears bit number b.
Examples
>
bit-clear(0b1100, 1)
12
Description
Sets bit number b.
Description
Checks if bit number b is set.
Examples
>
bit-test(0b0011, 1)
true
>
bit-test(0b1100, 1)
false
Description
Creates a new collection with all elements that pass the test implemented by fun.
Examples
>
filter(
["Albert", "Mojir", 160, [1, 2]],
string?
)
[
"Albert",
"Mojir"
]
>
filter(
[5, 10, 15, 20],
-> $ > 10
)
[15, 20]
>
filter(
{ a: 1, b: 2 },
odd?
)
{
"a": 1
}
Description
Creates a new collection with all elements that pass the test implemented by b. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.
Arguments
| a |
collection |
| b |
function |
The function to call for each element in the collection. The function should take two arguments: the element itself and the index.
|
Examples
>
filteri([1, 2, 3], (x, i) -> i % 2 == 0)
[1, 3]
>
filteri([1, 2, 3], (x, i) -> x % 2 == 0)
[2]
>
filteri([1, 2, 3], (x, i) -> x + i > 3)
[3]
Description
Creates a new collection populated with the results of calling fun on every element in colls.
Examples
>
[1, 2, 3] map -
[-1, -2, -3]
>
[1, 2, 3] map -> -($)
[-1, -2, -3]
>
map(["Albert", "Mojir", 42], str)
[
"Albert",
"Mojir",
"42"
]
>
map([1, 2, 3], inc)
[2, 3, 4]
>
map([1, 2, 3], [1, 10, 100], *)
[1, 20, 300]
>
map({ a: 1, b: 2 }, inc)
{
"a": 2,
"b": 3
}
>
map({ a: 1, b: 2 }, { a: 10, b: 20 }, +)
{
"a": 11,
"b": 22
}
Description
Creates a new collection populated with the results of calling b on every element in a. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.
Arguments
| a |
collection |
| b |
function |
The function to call for each element in the collection. The function should take two arguments: the element itself and the index.
|
Examples
>
mapi([1, 2, 3], (x, i) -> x + i)
[1, 3, 5]
>
mapi([1, 2, 3], (x, i) -> x * i)
[0, 2, 6]
>
mapi([1, 2, 3], (x, i) -> x - i)
[1, 1, 1]
>
mapi([1, 2, 3], (x, i) -> x / i)
[Infinity, 2, 1.5]
>
mapi([1, 2, 3], (x, i) -> x % inc(i))
[0, 0, 0]
| reduce(coll, fun, initial) |
→ |
any |
Description
Runs fun function on each element of the coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the coll is a single value.
Examples
>
reduce([1, 2, 3], +, 0)
6
>
reduce({ a: 1, b: 2 }, +, 0)
3
>
reduce(
[1, 2, 3, 4, 5, 6, 7, 8, 9],
(result, value) -> result + (even?(value) ? value : 0),
0)
20
| reduce-right(coll, fun, initial) |
→ |
any |
Description
Runs fun function on each element of the coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the coll is a single value.
Examples
>
reduce-right(["A", "B", "C"], str, "")
"CBA"
>
reduce-right({ a: 1, b: 2 }, +, 0)
3
| reducei-right(coll, fun, initial) |
→ |
any |
Description
Runs fun function on each element of the coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.
Arguments
| coll |
collection |
| fun |
function |
The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index.
|
| initial |
any |
The initial value to use as the accumulator.
|
Examples
>
reducei-right([1, 2, 3], (acc, x, i) -> acc + x + i, 0)
9
>
reducei-right("Albert", (acc, x, i) -> acc ++ x ++ i, "")
"t5r4e3b2l1A0"
>
reducei-right({ a: 1, b: 2 }, -> $1 ++ $3, "")
"ba"
| reducei(coll, fun, initial) |
→ |
any |
Description
Runs fun function on each element of the coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.
Arguments
| coll |
collection |
| fun |
function |
The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index.
|
| initial |
any |
The initial value to use as the accumulator.
|
Examples
>
reducei([1, 2, 3], (acc, x, i) -> acc + x + i, 0)
9
>
reducei("Albert", (acc, x, i) -> acc ++ x ++ i, "")
"A0l1b2e3r4t5"
>
reducei({ a: 1, b: 2 }, -> $1 ++ $3, "")
"ab"
| reductions(coll, fun, initial) |
→ |
Array<any> |
Description
Returns an array of the intermediate values of the reduction (see reduce) of coll by fun.
Examples
>
reductions([1, 2, 3], +, 0)
[0, 1, 3, 6]
>
reductions([1, 2, 3], +, 10)
[10, 11, 13, 16]
>
reductions([], +, 0)
[0]
>
reductions({ a: 1, b: 2 }, +, 0)
[0, 1, 3]
>
reductions(
[1, 2, 3, 4, 5, 6, 7, 8, 9],
(result, value) -> result + (even?(value) ? value : 0),
0
)
[
0,
0,
2,
2,
6,
6,
12,
12,
20,
20
]
| reductionsi(coll, fun, initial) |
→ |
Array<any> |
Description
Returns an array of the intermediate values of the reduction (see reduce) of coll by fun. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.
Arguments
| coll |
collection |
| fun |
function |
The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index.
|
| initial |
any |
The initial value to use as the accumulator.
|
Examples
>
reductionsi([1, 2, 3], (acc, x, i) -> acc + x + i, 0)
[0, 1, 4, 9]
>
reductionsi("Albert", (acc, x, i) -> acc ++ x ++ i, "")
[
"",
"A0",
"A0l1",
"A0l1b2",
"A0l1b2e3",
"A0l1b2e3r4",
"A0l1b2e3r4t5"
]
>
reductionsi({ a: 1, b: 2 }, -> $1 ++ $3, "")
[
"",
"a",
"ab"
]
Description
Returns number of elements in coll.
| a get b |
→ |
any |
| get(a, b) |
→ |
any |
| get(a, b, not-found) |
→ |
any |
Description
Returns value in a mapped at b.
Examples
>
get(
[1, 2, 3],
1, // Optional comma after last argument
)
2
>
get(
[],
1,
"default"
)
"default"
>
get(
{ a: 1 },
"b"
)
null
>
get(
{ a: 1 },
"b",
"default"
)
"default"
>
get(
null,
"b",
"default"
)
"default"
| a get-in b |
→ |
any |
| get-in(a, b) |
→ |
any |
| get-in(a, b, not-found) |
→ |
any |
Description
Returns the value in a nested collection, where b is an array of keys. Returns not-found if the key is not present. If not-found is not set, null is returned.
Examples
>
get-in(
[[1, 2, 3], [4, { a: "Kalle" }, 6]],
[1, 1, "a", 0]
)
"K"
>
get-in(
[[1, 2, 3], [4, { a: "Kalle" }, 6]],
[1, 1, "b", 0]
)
null
>
get-in(
[[1, 2, 3], [4, { a: "Kalle" }, 6]],
[1, 1, "b", 0],
"Lisa"
)
"Lisa"
Description
Returns true if a contains b, otherwise returns false. For strings, it checks if substring is included.
Examples
>
[1, 2, 3] contains? 1
true
>
{ a: 1, b: 2 } contains? "a"
true
>
contains?(
[],
1
)
false
>
contains?(
[1],
1
)
true
>
contains?(
[1, 2, 3],
1
)
true
>
contains?(
{},
"a"
)
false
>
contains?(
{ a: 1, b: 2 },
"a"
)
true
Description
Add or replace the value of element key to value in coll. Repeated for all key-value pairs in kvs.
If coll is an 'array', key must be number satisfying 0 <= key <= length.
Examples
>
assoc(
[1, 2, 3],
1,
"Two"
)
[
1,
"Two",
3
]
>
assoc(
[1, 2, 3],
3,
"Four"
)
[
1,
2,
3,
"Four"
]
>
assoc(
{ a: 1, b: 2 },
"a",
"One")
{
"a": "One",
"b": 2
}
>
assoc(
{ a: 1, b: 2 },
"c",
"Three")
{
"a": 1,
"b": 2,
"c": "Three"
}
>
assoc(
"Albert",
6,
"a")
"Alberta"
Description
Associates a value in the nested collection
coll, where
ks is an array of keys and
value is the new value.
If any levels do not exist, objects will be created - and the corresponding keys must be of type string.
Examples
>
assoc-in(
{},
["a", "b", "c"],
"Albert"
)
{
"a": {
"b": {
"c": "Albert"
}
}
}
>
assoc-in(
[1, 2, [1, 2, 3]],
[2, 1],
"Albert"
)
[
1,
2,
[
1,
"Albert",
3
]
]
>
assoc-in(
[1, 2, { name: "albert" }],
[2, "name", 0],
"A"
)
[
1,
2,
{
"name": "Albert"
}
]
Description
Concatenates collections into one collection.
Examples
>
"Albert" ++ " " ++ "Mojir"
"Albert Mojir"
>
"Albert" ++ "Mojir"
"AlbertMojir"
>
++("Albert", "-", "Mojir")
"Albert-Mojir"
>
++("A", "l", "b", "e", "r", "t")
"Albert"
>
++([1, 2], [3, 4])
[1, 2, 3, 4]
>
++([1, 2], [3, 4], [5, 6])
[1, 2, 3, 4, 5, 6]
>
++({ a: 1, b: 2 }, { b: 1, c: 2 })
{
"a": 1,
"b": 1,
"c": 2
}
>
++({}, { a: 1 })
{
"a": 1
}
Description
Returns null if coll is empty or null, otherwise coll.
Examples
>
not-empty([1, 2, 3])
[1, 2, 3]
>
not-empty({ a: 2 })
{
"a": 2
}
>
not-empty("Albert")
"Albert"
Description
Returns true if all entries in a pass the test implemented by b, otherwise returns false.
Examples
>
[1, 2, 3] every? number?
true
>
[1, 2, 3] every? even?
false
>
every?(
["Albert", "Mojir", 160, [1, 2]],
string?,
)
false
>
every?(
[50, 100, 150, 200],
-> $ > 10,
)
true
>
every?(
[],
number?
)
true
>
every?(
"",
number?
)
true
>
every?(
{},
number?
)
true
>
every?(
{ a: 2, b: 4},
-> even?(second($))
)
true
>
every?(
{ a: 2, b: 3 },
-> even?(second($))
)
false
Description
Returns true if at least one element in a does not pass the test implemented by b, otherwise returns false.
Examples
>
not-every?(
["Albert", "Mojir", 160, [1, 2]],
string?
)
true
>
not-every?(
[50, 100, 150, 200],
x -> x > 10
)
false
>
not-every?(
[],
number?
)
false
>
not-every?(
"",
number?
)
false
>
not-every?(
{},
number?
)
false
>
not-every?(
{ a: 2, b: 4 },
-> even?(second($))
)
false
>
not-every?(
{ a: 2, b: 3 },
-> even?(second($))
)
true
Description
Returns true if any element in a pass the test implemented by b, otherwise returns false.
Examples
>
any?(
["Albert", "Mojir", 160, [1, 2]],
string?
)
true
>
any?(
[50, 100, 150, 200],
x -> x > 10
)
true
>
any?(
[],
number?
)
false
>
any?(
"",
number?
)
false
>
any?(
{},
number?
)
false
>
any?(
{ a: 2, b: 3 },
-> even?(second($))
)
true
>
any?(
{ a: 1, b: 3 },
-> even?(second($))
)
false
Description
Returns false if any element in a pass the test implemented by b, otherwise returns true.
Examples
>
not-any?(
["Albert", "Mojir", 160, [1, 2]],
string?
)
false
>
not-any?(
[50, 100, 150, 200],
x -> x > 10
)
false
>
not-any?(
[],
number?
)
true
>
not-any?(
"",
number?
)
true
>
not-any?(
{},
number?
)
true
>
not-any?(
{ a: 2, b: 3 },
-> even?(second($))
)
false
>
not-any?(
{ a: 1, b: 3 },
-> even?(second($))
)
true
Description
Updates a value in the coll collection, where key is a key. fun is a function
that will take the old value and any supplied fun-args and
return the new value.
If the key does not exist, null is passed as the old value.
Examples
>
let x = { a: 1, b: 2 };
update(x, "a", inc)
{
"a": 2,
"b": 2
}
>
let x = { a: 1, b: 2 };
update(
x,
"c",
val -> null?(val) ? 0 : inc(val)
)
{
"a": 1,
"b": 2,
"c": 0
}
Description
Updates a value in the coll collection, where ks is an array of
keys and fun is a function that will take the old value and
any supplied fun-args and return the new value. If any levels do not exist,
objects will be created - and the corresponding keys must be of type string.
Examples
>
update-in(
{ a: [1, 2, 3] },
["a", 1],
-> null?($) ? 0 : inc($)
)
{
"a": [
1,
3,
3
]
}
>
update-in(
{ a: { foo: "bar"} },
["a", "foo"],
-> null?($) ? "?" : "!"
)
{
"a": {
"foo": "!"
}
}
>
update-in(
{ a: { foo: "bar"} },
["a", "baz"],
-> null?($) ? "?" : "!"
)
{
"a": {
"foo": "bar",
"baz": "?"
}
}
>
update-in(
{ a: [1, 2, 3] },
["a", 1],
*,
10,
10,
10,
)
{
"a": [
1,
2000,
3
]
}
Description
range creates an array with a range of numbers from
a to
b (exclusive), by
step.
a defaults to 0.
step defaults to 1.
Examples
>
1 range 10
[
1,
2,
3,
4,
5,
6,
7,
8,
9
]
>
range(0.4, 4.9)
[0.4, 1.4, 2.4, 3.4, 4.4]
>
range(
0.25, // start value
1, // end value (exclusive)
0.25, // step value
)
[0.25, 0.5, 0.75]
| a repeat b |
→ |
Array<any> |
| repeat(a, b) |
→ |
Array<any> |
Description
Returns an array with a repeated b times.
Examples
>
repeat(10, 3)
[10, 10, 10]
>
"Albert" repeat 5
[
"Albert",
"Albert",
"Albert",
"Albert",
"Albert"
]
Description
Takes a nested array x and flattens it.
Arguments
| x |
array | any |
If x is not an array, [ ] is returned.
|
Examples
>
flatten([1, 2, [3, 4], 5])
[1, 2, 3, 4, 5]
>
let foo = "bar";
flatten([
1,
" 2 A ",
[foo, [4, ["ABC"]]],
6,
])
[
1,
" 2 A ",
"bar",
4,
"ABC",
6
]
Description
Returns the result of applying concat to the result of applying map to fun and colls.
Examples
>
[[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]] mapcat reverse
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
]
>
mapcat([[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]], reverse)
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
]
>
[[3, 2, 1, 0,], [6, 5, 4,], [9, 8, 7]] mapcat reverse
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
]
>
let foo = (n) -> {
[n - 1, n, n + 1]
};
[1, 2, 3] mapcat foo
[
0,
1,
2,
1,
2,
3,
2,
3,
4
]
>
mapcat(
[[1, 2], [2, 2], [2, 3]],
-> $ remove even?
)
[1, 3]
| moving-fn(arr, windowSize, fn) |
→ |
array |
Description
Returns the result of applying fn to each moving window of size windowSize in arr.
Examples
>
let v = import("Vector"); moving-fn([1, 2, 3], 2, v.sum)
[3, 5]
>
let v = import("Vector"); moving-fn([1, 2, 3], 1, v.sum)
[1, 2, 3]
>
let v = import("Vector"); moving-fn([1, 2, 3], 3, v.sum)
[6]
Description
Returns the result of applying b to each element of a.
Examples
>
let v = import("Vector"); running-fn([1, 2, 3], v.sum)
[1, 3, 6]
>
let v = import("Vector"); running-fn([1, 2, 3], v.max)
[1, 2, 3]
>
let v = import("Vector"); running-fn([1, 2, 3], v.min)
[1, 1, 1]
| a nth b |
→ |
any |
| nth(seq, n) |
→ |
any |
| nth(seq, n, not-found) |
→ |
any |
Description
Accesses element n of seq. Accessing out-of-bounds indices returns not-found, if present, else null.
Examples
>
nth([1, 2, 3], -1)
null
>
nth([1, 2, 3], 3, 99)
99
>
nth("A string", -3)
null
>
nth("A string", 30, "X")
"X"
>
nth(null, 1, "Default value")
"Default value"
Description
Returns copy of seq with values added to the end of it.
Examples
>
[1, 2, 3] push 4
[1, 2, 3, 4]
>
"Albert" push "!"
"Albert!"
>
push([1, 2, 3], 4)
[1, 2, 3, 4]
>
push([1, 2, 3], 4, 5, 6)
[1, 2, 3, 4, 5, 6]
>
let l = [1, 2, 3];
push(l, 4);
l
[1, 2, 3]
Description
Returns a copy of seq with last element removed. If seq is empty null is returned.
Description
Returns copy of seq with values added to the beginning.
Examples
>
[1, 2, 3] unshift 4
[4, 1, 2, 3]
>
unshift([1, 2, 3], 4)
[4, 1, 2, 3]
>
unshift([1, 2, 3], 4, 5, 6)
[4, 5, 6, 1, 2, 3]
>
let l = [1, 2, 3];
unshift(l, 4);
l
[1, 2, 3]
Description
Returns a copy of seq with first element removed. If seq is empty null is returned.
Examples
>
shift([1, 2, 3])
[2, 3]
Description
Returns a copy of a portion of seq from index start (inclusive) to stop (exclusive).
Examples
>
[1, 2, 3, 4, 5] slice 2
[3, 4, 5]
>
slice([1, 2, 3, 4, 5], 2, 4)
[3, 4]
>
slice([1, 2, 3, 4, 5], 2)
[3, 4, 5]
| splice(...seq, start, deleteCount) |
→ |
sequence |
| splice(...seq, start, deleteCount, ...items) |
→ |
sequence |
Description
Returns a a spliced array. Removes deleteCount elements from seq starting at start and replaces them with items. If start is negative, it is counting from the end of the array.
Examples
>
splice([1, 2, 3, 4, 5], 2, 2, "x")
[
1,
2,
"x",
5
]
>
splice([1, 2, 3, 4, 5], -2, 1, "x")
[
1,
2,
3,
"x",
5
]
>
splice("Albert", 2, 2, "fo")
"Alfort"
Description
Returns the index of the first elements that passes the test implemented by fun. If no element was found, null is returned.
Examples
>
position(
["Albert", "Mojir", 160, [1, 2]],
string?
)
0
>
position(
[5, 10, 15, 20],
-> $ > 10
)
2
>
position(
[5, 10, 15, 20],
-> $ > 100
)
null
>
position(
null,
-> $ > 100
)
null
Description
Returns the index of x in seq. If element is not present in seq null is returned.
Examples
>
[[1], [2], [1], [2]] index-of [1]
0
>
index-of(["Albert", "Mojir", 160, [1, 2]], "Mojir")
1
>
index-of([5, 10, 15, 20], 15)
2
>
index-of([5, 10, 15, 20], 1)
null
Description
Returns the last index of x in seq. If element is not present in seq null is returned.
Examples
>
[[1], [2], [1], [2]] last-index-of [1]
2
>
last-index-of(["Albert", "Mojir", 160, [1, 2]], "Mojir")
1
>
last-index-of([5, 10, 15, 20, 15], 15)
4
>
last-index-of([5, 10, 15, 20], 1)
null
>
last-index-of(null, 1)
null
| a some b |
→ |
any |
| some(seq, fun) |
→ |
any |
Description
Returns the first element that passes the test implemented by fun. I no element was found, null is returned.
Examples
>
some(
["Albert", "Mojir", 160, [1, 2]],
string?
)
"Albert"
>
some(
[5, 10, 15, 20],
-> $ > 10
)
15
>
some(
[1, 2, 3, 4],
-> $ > 10
)
null
>
some(
[],
-> $ > 10
)
null
>
some(
null,
-> $ > 10
)
null
Description
If seq is an array, creates a new array with the elements from seq in reversed order. If seq is a string, returns new reversed string.
Examples
>
reverse(["Albert", "Mojir", 160, [1, 2]])
[
[
1,
2
],
160,
"Mojir",
"Albert"
]
>
reverse("Albert")
"treblA"
Description
Returns the first element of seq. If seq is empty or null, null is returned.
Examples
>
first(["Albert", "Mojir", 160, [1, 2]])
"Albert"
Description
Returns the second element of seq. If seq has less than two elements or is null, null is returned.
Examples
>
second(["Albert", "Mojir", 160, [1, 2]])
"Mojir"
Description
Returns the last element of seq. If seq is empty, null is returned.
Examples
>
last(["Albert", "Mojir", 160, [1, 2]])
[1, 2]
Description
If seq is an array, returns a new array with all but the first element from seq.
If seq has less than two elements, an empty array is returned.
For string seq returns all but the first characters in seq.
Examples
>
rest(["Albert", "Mojir", 160, [1, 2]])
[
"Mojir",
160,
[
1,
2
]
]
Description
If seq is an array, returns a new array with all but the first element from seq. If seq has less than two elements, null is returned. For string seq returns all but the first characters in seq. If length of string seq is less than two, null is returned.
Examples
>
next(["Albert", "Mojir", 160, [1, 2]])
[
"Mojir",
160,
[
1,
2
]
]
Description
Constructs a new array/string with the n first elements from seq.
Examples
>
[1, 2, 3, 4, 5] take 3
[1, 2, 3]
>
take([1, 2, 3, 4, 5], 3)
[1, 2, 3]
>
take([1, 2, 3, 4, 5], 0)
[]
>
take("Albert", 50)
"Albert"
Description
Constructs a new array with the n last elements from seq.
Examples
>
[1, 2, 3, 4, 5] take-last 3
[3, 4, 5]
>
take-last([1, 2, 3, 4, 5], 3)
[3, 4, 5]
>
take-last([1, 2, 3, 4, 5], 0)
[]
Description
Returns the members of seq in order, stopping before the first one for which predicate returns a falsy value.
Examples
>
take-while(
[1, 2, 3, 2, 1],
-> $ < 3
)
[1, 2]
>
take-while(
[1, 2, 3, 2, 1],
-> $ > 3
)
[]
Description
Constructs a new array/string with the n first elements dropped from seq.
Examples
>
drop([1, 2, 3, 4, 5], 3)
[4, 5]
>
drop([1, 2, 3, 4, 5], 0)
[1, 2, 3, 4, 5]
>
drop("Albert", 2)
"bert"
Description
Constructs a new array with the n last elements dropped from seq.
Examples
>
[1, 2, 3, 4, 5] drop-last 3
[1, 2]
>
drop-last([1, 2, 3, 4, 5], 3)
[1, 2]
>
drop-last([1, 2, 3, 4, 5], 0)
[1, 2, 3, 4, 5]
Description
Returns the members of seq in order, skipping the fist elements for witch the predicate returns a truethy value.
Examples
>
drop-while(
[1, 2, 3, 2, 1],
-> $ < 3
)
[3, 2, 1]
>
drop-while(
[1, 2, 3, 2, 1],
-> $ > 3
)
[1, 2, 3, 2, 1]
| a sort b |
→ |
Array<any> |
| sort(seq) |
→ |
Array<any> |
| sort(seq, fun) |
→ |
Array<any> |
Description
Returns a new sequence with the elements from seq sorted according to fun. If no fun is supplied, builtin compare will be used.
Examples
>
[3, 1, 2] sort (a, b) -> b - a
[3, 2, 1]
>
sort([3, 1, 2])
[1, 2, 3]
>
sort(
[3, 1, 2],
(a, b) -> cond case a < b then -1 case a > b then 1 case true then -1 end
)
[1, 2, 3]
>
sort(
[3, 1, 2],
(a, b) -> cond case a > b then -1 case a < b then 1 case true then -1 end
)
[3, 2, 1]
| a sort-by b |
→ |
Array<any> |
| sort-by(seq, keyfn) |
→ |
Array<any> |
| sort-by(seq, keyfn, comparer) |
→ |
Array<any> |
Description
Returns a sorted sequence of the items in seq, where the sort order is determined by comparing (keyfn item). If no comparer is supplied, uses builtin compare.
Examples
>
["Albert", "Mojir", "Nina"] sort-by count
[
"Nina",
"Mojir",
"Albert"
]
>
sort-by(["Albert", "Mojir", "Nina"], count)
[
"Nina",
"Mojir",
"Albert"
]
>
sort-by("Albert", lower-case, -> $2 compare $1)
"trlebA"
Description
Returns a copy of seq with no duplicates.
Examples
>
distinct([[1], [2], [3], [1], [3], [5]])
[ 1 ]
[ 2 ]
[ 3 ]
[ 5 ]
>
distinct([1, 2, 3, 1, 3, 5])
[1, 2, 3, 5]
>
distinct("Albert Mojir")
"Albert Moji"
Description
Returns a new sequence of items in seq for witch pred(item) returns a falsy value.
Examples
>
[1, 2, 3, 1, 3, 5] remove odd?
[2]
>
remove([1, 2, 3, 1, 3, 5], even?)
[1, 3, 1, 3, 5]
>
remove("Albert Mojir", -> "aoueiyAOUEIY" contains? $)
"lbrt Mjr"
Description
Returns a new sequence of all items in seq except item at position n. If n is negative, it is counting from the end of the sequence.
Examples
>
[1, 2, 3, 1, 3, 5] remove-at 2
[1, 2, 1, 3, 5]
>
"Albert" remove-at -2
"Albet"
>
remove-at([1, 2, 3, 1, 3, 5], 0)
[2, 3, 1, 3, 5]
>
remove-at([1, 2, 3, 1, 3, 5], -1)
[1, 2, 3, 1, 3]
>
remove-at("Albert Mojir", 6)
"AlbertMojir"
Description
Returns a pair of sequence [take(pos input), drop(pos input)].
Examples
>
[1, 2, 3, 4, 5] split-at 2
[
[
1,
2
],
[
3,
4,
5
]
]
>
"Albert" split-at -2
[
"Albe",
"rt"
]
>
split-at([1, 2, 3, 4, 5], -2)
[
[
1,
2,
3
],
[
4,
5
]
]
>
split-at("Albert", 2)
[
"Al",
"bert"
]
Description
Returns a pair of sequences [take-while(input, fun), drop-while(input, fun)].
Examples
>
[1, 2, 3, 4, 5] split-with odd?
[
[
1
],
[
2,
3,
4,
5
]
]
>
split-with([1, 2, 3, 4, 5], -> $ > 3)
[
[],
[
1,
2,
3,
4,
5
]
]
>
split-with("Albert", -> $ <= "o")
[
"Albe",
"rt"
]
Description
Returns an object from distinct items in seq to the number of times they appear. Note that all items in seq must be valid object keys i.e. strings.
Examples
>
frequencies(["Albert", "Mojir", "Nina", "Mojir"])
{
"Albert": 1,
"Mojir": 2,
"Nina": 1
}
>
frequencies("Pneumonoultramicroscopicsilicovolcanoconiosis")
{
"P": 1,
"n": 4,
"e": 1,
"u": 2,
"m": 2,
"o": 9,
"l": 3,
"t": 1,
"r": 2,
"a": 2,
"i": 6,
"c": 6,
"s": 4,
"p": 1,
"v": 1
}
Description
Returns an object of the elements of seq keyed by the result of fun on each element. The value at each key will be an array of the corresponding elements.
Examples
>
[{ name: "Albert" }, { name: "Albert" }, { name: "Mojir" }] group-by "name"
{
"Albert": [
{
"name": "Albert"
},
{
"name": "Albert"
}
],
"Mojir": [
{
"name": "Mojir"
}
]
}
>
group-by([{name: "Albert"}, {name: "Albert"}, {name: "Mojir"}], "name")
{
"Albert": [
{
"name": "Albert"
},
{
"name": "Albert"
}
],
"Mojir": [
{
"name": "Mojir"
}
]
}
>
group-by("Albert Mojir", -> "aoueiAOUEI" contains? $ ? "vowel" : "other")
{
"vowel": [
"A",
"e",
"o",
"i"
],
"other": [
"l",
"b",
"r",
"t",
" ",
"M",
"j",
"r"
]
}
Description
Returns an array of sequences of n items each, at offsets step apart. If step is not supplied, defaults to n. If a pad array is supplied, use its elements as necessary to complete last partition upto n items. In case there are not enough padding elements, return a partition with less than n items.
Examples
>
range(20) partition 4
[ 0 1 2 3 ]
[ 4 5 6 7 ]
[ 8 9 10 11 ]
[ 12 13 14 15 ]
[ 16 17 18 19 ]
>
partition(range(20), 4)
[ 0 1 2 3 ]
[ 4 5 6 7 ]
[ 8 9 10 11 ]
[ 12 13 14 15 ]
[ 16 17 18 19 ]
>
partition(range(22), 4)
[ 0 1 2 3 ]
[ 4 5 6 7 ]
[ 8 9 10 11 ]
[ 12 13 14 15 ]
[ 16 17 18 19 ]
>
partition(range(20), 4, 6)
[ 0 1 2 3 ]
[ 6 7 8 9 ]
[ 12 13 14 15 ]
>
partition(range(20), 4, 3)
[ 0 1 2 3 ]
[ 3 4 5 6 ]
[ 6 7 8 9 ]
[ 9 10 11 12 ]
[ 12 13 14 15 ]
[ 15 16 17 18 ]
>
partition(range(20), 3, 6, ["a"])
[
[
0,
1,
2
],
[
6,
7,
8
],
[
12,
13,
14
],
[
18,
19,
"a"
]
]
>
partition(range(20), 4, 6, ["a"])
[
[
0,
1,
2,
3
],
[
6,
7,
8,
9
],
[
12,
13,
14,
15
],
[
18,
19,
"a"
]
]
>
partition(range(20), 4, 6, ["a", "b", "c", "d"])
[
[
0,
1,
2,
3
],
[
6,
7,
8,
9
],
[
12,
13,
14,
15
],
[
18,
19,
"a",
"b"
]
]
>
partition(["a", "b", "c", "d", "e", "f"], 3, 1)
[
[
"a",
"b",
"c"
],
[
"b",
"c",
"d"
],
[
"c",
"d",
"e"
],
[
"d",
"e",
"f"
]
]
>
partition([1, 2, 3, 4], 10)
[]
>
partition([1, 2, 3, 4], 10, 10)
[]
>
partition([1, 2, 3, 4], 10, 10, [])
[ 1 2 3 4 ]
>
partition([1, 2, 3, 4], 10, 10, null)
[ 1 2 3 4 ]
>
partition("superfragilistic", 5)
[
"super",
"fragi",
"listi"
]
>
partition("superfragilistic", 5, 5, null)
[
"super",
"fragi",
"listi",
"c"
]
>
let foo = [5, 6, 7, 8]; partition(foo, 2, 1, foo)
[ 5 6 ]
[ 6 7 ]
[ 7 8 ]
[ 8 5 ]
Description
Returns an array of sequences like partition, but may include partitions with fewer than n items at the end.
Examples
>
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] partition-all 4
[
[
0,
1,
2,
3
],
[
4,
5,
6,
7
],
[
8,
9
]
]
>
partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)
[
[
0,
1,
2,
3
],
[
4,
5,
6,
7
],
[
8,
9
]
]
>
partition([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)
[ 0 1 2 3 ]
[ 4 5 6 7 ]
>
partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 4)
[ 0 1 ]
[ 4 5 ]
[ 8 9 ]
Description
Applies fun to each value in seq, splitting it each time fun returns a new value. Returns an array of sequences.
Examples
>
[1, 2, 3, 4, 5] partition-by odd?
[ 1 ]
[ 2 ]
[ 3 ]
[ 4 ]
[ 5 ]
>
partition-by([1, 2, 3, 4, 5], -> $ == 3)
[
[
1,
2
],
[
3
],
[
4,
5
]
]
>
partition-by([1, 1, 1, 2, 2, 3, 3], odd?)
[
[
1,
1,
1
],
[
2,
2
],
[
3,
3
]
]
>
partition-by("Leeeeeerrroyyy", identity)
[
"L",
"eeeeee",
"rrr",
"o",
"yyy"
]
Description
Returns true if seq starts with prefix, otherwise false.
Examples
>
[[1], [2], [3], [4], [5]] starts-with? [1]
true
>
starts-with?([1, 2, 3, 4, 5], 1)
true
>
starts-with?([1, 2, 3, 4, 5], [1])
false
>
starts-with?("Albert", "Al")
true
>
starts-with?("Albert", "al")
false
Description
Returns true if seq ends with suffix, otherwise false.
Examples
>
[[1], [2], [3], [4], [5]] starts-with? [5]
false
>
[[1], [2], [3], [4], [5]] starts-with? 5
false
>
ends-with?([1, 2, 3, 4, 5], 5)
true
>
ends-with?([1, 2, 3, 4, 5], [5])
false
>
ends-with?("Albert", "rt")
true
>
ends-with?("Albert", "RT")
false
Description
Returns a sequence of the first item from each of the seqs, then the second item from each of the seqs, until all items from the shortest seq are exhausted.
Examples
>
[1, 2, 3] interleave [4, 5, 6]
[1, 4, 2, 5, 3, 6]
>
"Albert" interleave ".,.,.,"
"A.l,b.e,r.t,"
>
interleave([1, 2, 3], [4, 5, 6])
[1, 4, 2, 5, 3, 6]
>
interleave([1, 2, 3], [4, 5, 6], [7, 8, 9])
[
1,
4,
7,
2,
5,
8,
3,
6,
9
]
>
interleave([1, 2, 3], [4, 5, 6], [7, 8])
[1, 4, 7, 2, 5, 8]
>
interleave([1, 2, 3], [4, 5, 6], [7])
[1, 4, 7]
>
interleave([1, 2, 3], [4, 5, 6], [])
[]
>
interleave([1, 2, 3], [])
[]
Description
Returns a sequence of the elements of seq separated by separator. If seq is a string, the separator must be a string.
Examples
>
"Albert" interpose "-"
"A-l-b-e-r-t"
>
interpose([1, 2, 3, 4, 5], "a")
[
1,
"a",
2,
"a",
3,
"a",
4,
"a",
5
]
>
interpose(["Albert", "Mojir", "Nina"], ", ")
[
"Albert",
", ",
"Mojir",
", ",
"Nina"
]
>
interpose("Albert", ".")
"A.l.b.e.r.t"
Description
The + function performs addition of numbers and element-wise addition of vectors and matrices of compatible dimensions, returning the same type as its inputs. When used with mixed types, it adds the scalar to each element of the collection.
Examples
>
[1, 2, 3] + 2
[3, 4, 5]
>
[1, 2, 3] + [4, 5, 6]
[5, 7, 9]
>
[[1, 2, 3], [4, 5, 6]] + [[7, 8, 9], [10, 11, 12]]
[ 8 10 12 ]
[ 14 16 18 ]
>
[[1, 2, 3], [4, 5, 6]] + 2
[ 3 4 5 ]
[ 6 7 8 ]
Description
Computes difference between first value and sum of the rest. When called with only one argument, it does negation.
Examples
>
[1, 2, 3] - 2
[-1, 0, 1]
>
[1, 2, 3] - [4, 5, 6]
[-3, -3, -3]
>
[[1, 2, 3], [4, 5, 6]] - [[7, 8, 9], [10, 11, 12]]
[ -6 -6 -6 ]
[ -6 -6 -6 ]
>
[[1, 2, 3], [4, 5, 6]] - 2
[ -1 0 1 ]
[ 2 3 4 ]
Description
The * function performs multiplication of numbers and element-wise multiplication of vectors and matrices of compatible dimensions, returning the same type as its inputs. When used with mixed types, it multiplies each element of the collection by the scalar.
Examples
>
[1, 2, 3] * 2
[2, 4, 6]
>
[1, 2, 3] * [4, 5, 6]
[4, 10, 18]
>
[[1, 2, 3], [4, 5, 6]] * [[7, 8, 9], [10, 11, 12]]
[ 7 16 27 ]
[ 40 55 72 ]
>
[[1, 2, 3], [4, 5, 6]] * 2
[ 2 4 6 ]
[ 8 10 12 ]
Description
The / function performs division of numbers and element-wise division of vectors and matrices of compatible dimensions, returning the same type as its inputs. When used with mixed types, it divides each element of the collection by the scalar.
Examples
>
[1, 2, 3] / 2
[0.5, 1, 1.5]
>
[1, 2, 3] / [4, 5, 6]
[0.25, 0.4, 0.5]
>
[[1, 2, 3], [4, 5, 6]] / [[7, 8, 9], [10, 11, 12]]
[ 0.14285714285714285 0.25 0.3333333333333333 ]
[ 0.4 0.45454545454545453 0.5 ]
>
[[1, 2, 3], [4, 5, 6]] / 2
[ 0.5 1 1.5 ]
[ 2 2.5 3 ]
Description
The mod function computes the modulo of division with the same sign as the divisor, working on numbers and element-wise on vectors and matrices of compatible dimensions. When used with mixed types, it applies the modulo operation between each element of the collection and the scalar.
Examples
>
[1, 2, 3] mod 2
[1, 0, 1]
>
2 mod [1, 2, 3]
[0, 0, 2]
>
mod([1, 2, 3], [4, 5, 6])
[1, 2, 3]
>
[[1, 2, 3], [4, 5, 6]] mod [[7, 8, 9], [10, 11, 12]]
[ 1 2 3 ]
[ 4 5 6 ]
>
mod([[1, 2, 3], [4, 5, 6]], 2)
[ 1 0 1 ]
[ 0 1 0 ]
Description
The % function computes the remainder of division with the same sign as the dividend, working on numbers and element-wise on vectors and matrices of compatible dimensions. When used with mixed types, it applies the remainder operation between each element of the collection and the scalar.
Examples
>
[1, 2, 3] % 2
[1, 0, 1]
>
2 % [1, 2, 3]
[0, 0, 2]
>
%([1, 2, 3], [4, 5, 6])
[1, 2, 3]
>
[[1, 2, 3], [4, 5, 6]] % [[7, 8, 9], [10, 11, 12]]
[ 1 2 3 ]
[ 4 5 6 ]
>
%([[1, 2, 3], [4, 5, 6]], 2)
[ 1 0 1 ]
[ 0 1 0 ]
Description
The quot function performs integer division truncated toward zero, working on numbers and element-wise on vectors and matrices of compatible dimensions. When used with mixed types, it applies integer division between each element of the collection and the scalar.
Examples
>
[1, 2, 3] quot 2
[0, 1, 1]
>
2 quot [1, 2, 3]
[2, 1, 0]
>
quot([1, 2, 3], [4, 5, 6])
[0, 0, 0]
>
[[1, 2, 3], [4, 5, 6]] quot [[7, 8, 9], [10, 11, 12]]
[ 0 0 0 ]
[ 0 0 0 ]
>
quot([[1, 2, 3], [4, 5, 6]], 2)
[ 0 1 1 ]
[ 2 2 3 ]
>
[[1, 2, 3], [4, 5, 6]] quot [[7, 8, 9], [10, 11, 12]]
[ 0 0 0 ]
[ 0 0 0 ]
Description
The inc function increments its argument by 1, working on numbers and element-wise on vectors and matrices. When applied to collections, it increases each element by 1 while preserving the original structure.
Examples
>
inc([1, 2, 3])
[2, 3, 4]
>
inc([[1, 2], [3, 4]])
[ 2 3 ]
[ 4 5 ]
Description
The dec function decrements its argument by 1, working on numbers and element-wise on vectors and matrices. When applied to collections, it decreases each element by 1 while preserving the original structure.
Examples
>
dec([1, 2, 3])
[0, 1, 2]
>
dec([[1, 2], [3, 4]])
[ 0 1 ]
[ 2 3 ]
Description
The sqrt function calculates the square root of numbers and computes element-wise square roots of vectors and matrices. When applied to collections, it returns the square root of each element while preserving the original structure.
Examples
>
sqrt(2)
1.4142135623730951
>
sqrt(2)
1.4142135623730951
>
sqrt([1, 4, 9])
[1, 2, 3]
>
sqrt([[1, 4], [9, 16]])
[ 1 2 ]
[ 3 4 ]
Description
The cbrt function calculates the cube root of numbers and computes element-wise cube roots of vectors and matrices. When applied to collections, it returns the cube root of each element while preserving the original structure.
Examples
>
cbrt(2)
1.2599210498948732
>
cbrt(2)
1.2599210498948732
>
cbrt([1, 8, 27])
[1, 2, 3]
>
cbrt([[1, 8], [27, 64]])
[ 1 2 ]
[ 3 4 ]
Description
The ^ function computes exponentiation, raising the first argument to the power of the second, working on numbers and element-wise on vectors and matrices of compatible dimensions. When used with mixed types, it applies the power operation between each element of the collection and the scalar.
Examples
>
[1, 2, 3] ^ 2
[1, 4, 9]
>
2 ^ [1, 2, 3]
[2, 4, 8]
>
^([1, 2, 3], [4, 5, 6])
[1, 32, 729]
>
[[1, 2, 3], [4, 5, 6]] ^ [[7, 8, 9], [10, 11, 12]]
[ 1 256 19683 ]
[ 1048576 48828125 2176782336 ]
>
^([[1, 2, 3], [4, 5, 6]], 2)
[ 1 4 9 ]
[ 16 25 36 ]
Description
The round function rounds a number to the nearest integer or to a specified number of decimal places, working on numbers and element-wise on vectors and matrices. When applied to collections, it rounds each element while preserving the original structure.
Examples
>
round(1.23456789, 4)
1.2346
>
1.123456789 round 2
1.12
>
round([1.23456789, 2.3456789], 1)
[1.2, 2.3]
>
[1.23456789, 2.3456789] round 4
[1.2346, 2.3457]
>
[[1.23456789, 2.3456789], [3.456789, 4.56789]] round 4
[ 1.2346 2.3457 ]
[ 3.4568 4.5679 ]
>
round([[1.23456789, 2.3456789], [3.456789, 4.56789]], 2)
[ 1.23 2.35 ]
[ 3.46 4.57 ]
Description
The trunc function truncates numbers toward zero (removing decimal portions without rounding), working on numbers and element-wise on vectors and matrices. When applied to collections, it truncates each element while preserving the original structure.
Examples
>
trunc([1.23456789, 2.3456789])
[1, 2]
>
trunc([[1.23456789, 2.3456789], [3.456789, 4.56789]])
[ 1 2 ]
[ 3 4 ]
Description
The floor function returns the largest integer less than or equal to a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the floor of each element while preserving the original structure.
Examples
>
floor([1.23456789, 2.3456789])
[1, 2]
>
floor([[1.23456789, 2.3456789], [3.456789, 4.56789]])
[ 1 2 ]
[ 3 4 ]
Description
The ceil function returns the smallest integer greater than or equal to a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the ceiling of each element while preserving the original structure.
Examples
>
ceil([1.23456789, 2.3456789])
[2, 3]
>
ceil([[1.23456789, 2.3456789], [3.456789, 4.56789]])
[ 2 3 ]
[ 4 5 ]
Description
Returns the smallest number of the arguments.
Description
Returns the largest number of the arguments.
Description
The abs function returns the absolute value (magnitude) of a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the absolute value of each element while preserving the original structure.
Examples
>
abs([1, -2, 3])
[1, 2, 3]
>
abs([[1, -2], [3, -4]])
[ 1 2 ]
[ 3 4 ]
Description
The sign function returns the sign** of a **number (-1 for negative, 0 for zero, 1 for positive), working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the sign of each element while preserving the original structure.
Examples
>
sign([1, -2, 3])
[1, -1, 1]
>
sign([[1, -2], [3, -4]])
[ 1 -1 ]
[ 1 -1 ]
Description
The ln function computes the natural logarithm (base e) of a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the natural logarithm of each element while preserving the original structure.
Examples
>
ln(0.01)
-4.605170185988091
>
ln(2.5)
0.9162907318741551
>
ln([1, 2, 3])
[0, 0.6931471805599453, 1.0986122886681096]
>
ln([[1, 2], [3, 4]])
[ 0 0.6931471805599453 ]
[ 1.0986122886681096 1.3862943611198906 ]
Description
The log2 function computes the base 2 logarithm of a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the base-2 logarithm of each element while preserving the original structure.
Examples
>
log2(0.01)
-6.643856189774724
>
log2(2.5)
1.3219280948873624
>
log2([1, 2, 3])
[0, 1, 1.584962500721156]
>
log2([[1, 2], [3, 4]])
[ 0 1 ]
[ 1.584962500721156 2 ]
Description
The log10 function computes the base 10 logarithm of a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the base-10 logarithm of each element while preserving the original structure.
Examples
>
log10(2.5)
0.3979400086720376
>
log10([1, 2, 3])
[0, 0.3010299956639812, 0.47712125471966244]
>
log10([[1, 2], [3, 4]])
[ 0 0.3010299956639812 ]
[ 0.47712125471966244 0.6020599913279624 ]
Description
The sin function computes the sine of an angle (in radians), working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the sine of each element while preserving the original structure.
Examples
>
sin(1)
0.8414709848078965
>
sin(PI)
1.2246467991473532e-16
>
sin(-0.5)
-0.479425538604203
>
sin([1, 2, 3])
[0.8414709848078965, 0.9092974268256817, 0.1411200080598672]
>
sin([[1, 2], [3, 4]])
[ 0.8414709848078965 0.9092974268256817 ]
[ 0.1411200080598672 -0.7568024953079282 ]
Description
The cos function computes the cosine of an angle (in radians), working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the cosine of each element while preserving the original structure.
Examples
>
cos(1)
0.5403023058681398
>
cos(-0.5)
0.8775825618903728
>
cos([1, 2, 3])
[0.5403023058681398, -0.4161468365471424, -0.9899924966004454]
>
cos([[1, 2], [3, 4]])
[ 0.5403023058681398 -0.4161468365471424 ]
[ -0.9899924966004454 -0.6536436208636119 ]
Description
The tan function computes the tangent of an angle (in radians), working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the tangent of each element while preserving the original structure.
Examples
>
tan(1)
1.5574077246549023
>
tan(PI)
-1.2246467991473532e-16
>
tan(-0.5)
-0.5463024898437905
>
tan([1, 2, 3])
[1.5574077246549023, -2.185039863261519, -0.1425465430742778]
>
tan([[1, 2], [3, 4]])
[ 1.5574077246549023 -2.185039863261519 ]
[ -0.1425465430742778 1.1578212823495777 ]
Description
The asin function computes the arcsine (inverse sine) of a number in radians, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the arcsine of each element while preserving the original structure.
Examples
>
asin(1)
1.5707963267948966
>
asin(-0.5)
-0.5235987755982989
>
asin([1, 2, 3])
[
1.5707963267948966,
null,
null
]
>
asin([[1, 2], [3, 4]])
[
[
1.5707963267948966,
null
],
[
null,
null
]
]
Description
The acos function computes the arccosine (inverse cosine) of a number in radians, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the arccosine of each element while preserving the original structure.
Examples
>
acos(0)
1.5707963267948966
>
acos(-0.5)
2.0943951023931957
>
acos([0.1, 0.2, 0.3])
[1.4706289056333368, 1.369438406004566, 1.2661036727794992]
>
acos([[0.1, 0.2], [0.3, 0.4]])
[ 1.4706289056333368 1.369438406004566 ]
[ 1.2661036727794992 1.1592794807274085 ]
Description
The atan function computes the arctangent (inverse tangent) of a number in radians, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the arctangent of each element while preserving the original structure.
Examples
>
atan(1)
0.7853981633974483
>
atan(-0.5)
-0.4636476090008061
>
atan([0.1, 0.2, 0.3])
[0.09966865249116204, 0.19739555984988078, 0.2914567944778671]
>
atan([[0.1, 0.2], [0.3, 0.4]])
[ 0.09966865249116204 0.19739555984988078 ]
[ 0.2914567944778671 0.3805063771123649 ]
Description
The sinh function computes the hyperbolic sine of a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the hyperbolic sine of each element while preserving the original structure.
Examples
>
sinh(1)
1.1752011936438014
>
sinh(-0.5)
-0.5210953054937474
>
sinh([0.1, 0.2, 0.3])
[0.10016675001984403, 0.20133600254109402, 0.3045202934471426]
>
sinh([[0.1, 0.2], [0.3, 0.4]])
[ 0.10016675001984403 0.20133600254109402 ]
[ 0.3045202934471426 0.4107523258028155 ]
Description
The cosh function computes the hyperbolic cosine of a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the hyperbolic cosine of each element while preserving the original structure.
Examples
>
cosh(1)
1.5430806348152437
>
cosh(-0.5)
1.1276259652063807
>
cosh([0.1, 0.2, 0.3])
[1.0050041680558035, 1.020066755619076, 1.0453385141288605]
>
cosh([[0.1, 0.2], [0.3, 0.4]])
[ 1.0050041680558035 1.020066755619076 ]
[ 1.0453385141288605 1.081072371838455 ]
Description
The tanh function computes the hyperbolic tangent of a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the hyperbolic tangent of each element while preserving the original structure.
Examples
>
tanh(1)
0.7615941559557649
>
tanh(-0.5)
-0.46211715726000974
Description
The asinh function computes the inverse hyperbolic sine of a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the inverse hyperbolic sine of each element while preserving the original structure.
Examples
>
asinh(10)
2.99822295029797
>
asinh(90)
5.192987713658941
>
asinh (50)
4.605270170991424
>
asinh([10, 20, 30])
[2.99822295029797, 3.6895038689889055, 4.09462222433053]
>
asinh([[10, 20], [30, 40]])
[ 2.99822295029797 3.6895038689889055 ]
[ 4.09462222433053 4.382182848065498 ]
Description
The acosh function computes the inverse hyperbolic cosine of a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the inverse hyperbolic cosine of each element while preserving the original structure.
Examples
>
acosh(2)
1.3169578969248166
>
acosh(100)
5.298292365610484
>
acosh(50)
4.6050701709847575
>
acosh([1, 2, 3])
[0, 1.3169578969248166, 1.7627471740390859]
>
acosh([[1, 2], [3, 4]])
[ 0 1.3169578969248166 ]
[ 1.7627471740390859 2.0634370688955608 ]
Description
The atanh function computes the inverse hyperbolic tangent of a number, working on numbers and element-wise on vectors and matrices. When applied to collections, it returns the inverse hyperbolic tangent of each element while preserving the original structure.
Examples
>
atanh(0.9)
1.4722194895832204
>
atanh(-0.5)
-0.5493061443340548
>
atanh([0.1, 0.2, 0.3])
[0.10033534773107558, 0.2027325540540822, 0.30951960420311175]
>
atanh([[0.1, 0.2], [0.3, 0.4]])
[ 0.10033534773107558 0.2027325540540822 ]
[ 0.30951960420311175 0.42364893019360184 ]
Description
The to-rad function converts an angle from degrees to radians, working on numbers and element-wise on vectors and matrices. When applied to collections, it converts each element while preserving the original structure.
Examples
>
to-rad(90)
1.5707963267948966
>
to-rad(180)
3.141592653589793
>
to-rad(360)
6.283185307179586
>
to-rad([0, 90, 180])
[0, 1.5707963267948966, 3.141592653589793]
>
to-rad([[0, 90], [180, 360]])
[ 0 1.5707963267948966 ]
[ 3.141592653589793 6.283185307179586 ]
Description
The to-deg function converts an angle from radians to degrees, working on numbers and element-wise on vectors and matrices. When applied to collections, it converts each element while preserving the original structure.
Examples
>
to-deg([0, PI, PI / 2])
[0, 180, 90]
>
to-deg([[0, PI], [PI / 2, 3 * PI / 2]])
[ 0 180 ]
[ 90 270 ]
Description
Takes a value a and a function b, and returns the result of applying b to a.
Examples
>
range(10)
|> map(_, -> $ ^ 2) // [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
|> filter(_, odd?) // [1, 9, 25, 49, 81]
|> reduce(_, +, 0) // 165
|> sqrt // 12.84523257866513
|> round(_, 2)
12.85
| a apply b |
→ |
any |
| apply(fun, args) |
→ |
any |
Description
Call supplied function fun with specified arguments args.
Examples
>
apply(
(x, y) -> sqrt(x ^ 2 + y ^ 2),
[3, 4]
)
5
>
(x, y) -> sqrt(x ^ 2 + y ^ 2) apply [3, 4]
<function λ>
Examples
>
identity("Albert")
"Albert"
>
identity({ a: 1 })
{
"a": 1
}
Description
Takes a variable number of functions and returns a function that is the composition of those.
The returned function takes a variable number of arguments,
applies the rightmost function to the args,
the next function (right-to-left) to the result, etc.
Examples
>
let negative-quotient = comp(-, /);
negative-quotient(9, 3)
-3
>
let x = { bar: { foo: 42 } };
comp("foo", "bar")(x)
42
Description
Returns a function that takes any number of arguments and always returns x.
Examples
>
let always-true = constantly(true);
always-true(9, 3)
true
Description
Takes one or many function and returns a function that is the juxtaposition of those functions.
The returned function takes a variable number of args,
and returns a vector containing the result of applying each function to the args (left-to-right).
Examples
>
juxt(+, *, min, max)(
3,
4,
6,
)
[13, 72, 3, 6]
>
juxt("a", "b")(
{
a: 1,
b: 2,
c: 3,
d: 4
}
)
[1, 2]
>
juxt(+, *, min, max) apply range(1, 11)
[55, 3628800, 1, 10]
Description
Takes a function fun and returns a new function that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.
Examples
>
complement(>)(1, 3)
true
>
complement(<)(1, 3)
false
>
complement(+)(1, 3)
false
>
complement(+)(0, 0)
true
Description
Takes a number of predicates and returns a function that returns true if all predicates
return a truthy value against all of its arguments, else it returns false.
Examples
>
every-pred(string?, -> count($) > 3)(
"Albert",
"Mojir"
)
true
>
(string? every-pred -> count($) > 3)(
"Albert",
"M"
)
false
Description
Takes a number of predicates and returns a function that returns true if at least one of the predicates return a truthy true value against at least one of its arguments, else it returns false.
Examples
>
some-pred(string?, -> count($) > 3)("Albert", "Mojir")
true
>
some-pred(string?, -> count($) > 3)("a", "M")
true
>
some-pred(string?, -> count($) > 3)("a", [1, 2, 3])
true
>
some-pred(string?, -> count($) > 3)([1, 2, 3], [2])
false
Description
Takes a function fun, and returns a function that calls fun, replacing a null argument to the corresponding argument.
Examples
>
fnull(+, 1, 2)(null, 0)
1
>
fnull(+, 1, 2)(0, null)
2
>
fnull(+, 1, 2)(null, null)
3
>
fnull(+, 1, 2)(null, null, 3, 4)
10
Description
Returns documentation string of the fun.
Examples
>
doc(+)
"+
The + function performs addition of numbers and element-wise addition of vectors and matrices of compatible dimensions, returning the same type as its inputs. When used with mixed types, it adds the scalar to each element of the collection.
Signature:
+(...xs) -> number | vector | matrix
Operator:
a + b -> number | vector | matrix
Arguments:
xs: Array
a: number | vector | matrix
b: number | vector | matrix
Examples:
1 + 2
1 + 20 + 30
+(1, 2, 3, 4)
+()
+(1)
[1, 2, 3] + 2
[1, 2, 3] + [4, 5, 6]
[[1, 2, 3], [4, 5, 6]] + [[7, 8, 9], [10, 11, 12]]
[[1, 2, 3], [4, 5, 6]] + 2"
>
let add = (x, y) -> {
"""
Adds two numbers.
Args:
x: First number.
y: Second number.
Returns:
Sum of x and y.
"""
x + y;
};
doc(add)
"Adds two numbers.
Args:
x: First number.
y: Second number.
Returns:
Sum of x and y."
Description
Returns arity of the fun. The arity is an object with the properties: min and max. If the function has fixed arity, min and max are equal to the number of required parameters. If no restrictions apply, empty object is returned.
Examples
>
arity(defined?)
{
"min": 1,
"max": 1
}
>
let add = (x, y = 0) -> {
x + y;
};
arity(add)
{
"min": 1,
"max": 2
}
>
let foo = (k, ...x) -> {
k + x;
};
arity(foo)
{
"min": 1
}
Description
Returns true if all values are not equal to each other, otherwise result is false. (≠ a b c) is same as (! (== a b c)).
Examples
>
≠("3", "2", "1", "0",)
true
Description
Returns true if all values are structaul equal to each other, otherwise result is false.
Examples
>
{
a: 1,
b: 2,
} == {
b: 2,
a: 1,
}
true
>
==("2", "2", "2", "2")
true
>
==([1, 2], [1, 2])
true
>
==({ a: 1, b: 2 }, { b: 2, a: 1 })
true
Description
Returns true if x and ys are in increasing order, false otherwise.
Description
Returns true if x and ys are in decreasing order, false otherwise.
Description
Returns true if x and ys are in non decreasing order, false otherwise.
Description
Returns true if x and ys are in non increasing order, false otherwise.
Description
Computes logical negation. Note that any other x than false, 0, null and '' is truthy.
Description
It logs the values and then returns the last argument. If called with no arguments null is returned.
Examples
>
write!("A string")
"A string"
>
write!(100, "items")
"items"
>
write!(object("a", 10))
{
"a": 10
}
>
write!(["a", "b", "c"])
[
"a",
"b",
"c"
]
>
write!(#"^start")
/^start/
>
write!(null, true, false)
false
Description
Returns milliseconds elapsed since the UNIX epoch to iso.
Examples
>
iso-date->epoch("2022-04-12T09:37:10.899Z")
1649756230899
>
iso-date->epoch("1980-01-01")
315532800000
Description
Returns IOS date time string from ms (milliseconds elapsed since the UNIX epoch).
Examples
>
epoch->iso-date(1649756230899)
"2022-04-12T09:37:10.899Z"
>
epoch->iso-date(0)
"1970-01-01T00:00:00.000Z"
Description
Coerces x to boolean.
Description
Compares two values. Returns -1 if a < b, 1 if a > b and 0 if a and b have the same sort order.
Examples
>
compare("Albert", "Mojir")
-1
Description
Returns true if a and b are referential equal.
Examples
>
identical?({ a: 10, b: 20 }, { b: 20, a: 10 })
false
>
identical?([1, true, null], [1, true, null])
false
>
identical?(0.3, 0.1 + 0.2)
false
Description
Imports namespace functions. Use a namespace name (e.g., "Vector") to import all functions as an object, or a fully qualified name (e.g., "Vector.mean") to import a single function directly.
Arguments
| path |
string |
The namespace path to import. Can be a namespace name (e.g., "Vector", "Grid") or a fully qualified function name (e.g., "Vector.mean", "Grid.row").
|
Examples
>
let v = import("Vector"); v.mean([1, 2, 3, 4])
2.5
>
let sum = import("Vector.sum"); sum([1, 2, 3])
6
>
let g = import("Grid"); g.row([[1, 2], [3, 4]], 0)
[1, 2]
Description
Returns JSON.parse(x).
Examples
>
json-parse("[1, 2, 3]")
[1, 2, 3]
| json-stringify(x) |
→ |
string |
| json-stringify(x, indent) |
→ |
string |
Description
Returns JSON.stringify(x). If second argument is provided, returns JSON.stringify(x, null, indent).
Arguments
| x |
any |
| indent |
integer |
Number of spaces to use for indentation.
|
Examples
>
json-stringify([1, 2, 3])
"[1,2,3]"
>
json-stringify({ a: { b: 10 }}, 2)
"{
"a": {
"b": 10
}
}"
Description
Return shallow copy of obj with key deleted.
Examples
>
{ x: 10, y: 20 } dissoc "y"
{
"x": 10
}
>
dissoc({ x: 10, y: 20 }, "x")
{
"y": 20
}
>
dissoc({ x: 10 }, "y")
{
"x": 10
}
>
let o = { a: 5 };
dissoc(o, "a");
o
{
"a": 5
}
Description
Returns array of all keys in obj.
Examples
>
keys({ x: 10, y: true, z: "A string" })
[
"x",
"y",
"z"
]
>
keys(object("x", 10, "y", true, "z", "A string"))
[
"x",
"y",
"z"
]
Description
Returns array of all values in obj.
Examples
>
vals({ x: 10, y: true, z: "A string" })
[
10,
true,
"A string"
]
>
vals(object("x", 10, "y", true, "z", "A string"))
[
10,
true,
"A string"
]
Description
Returns nested array of all key - value pairs in obj.
Examples
>
entries({ x: 10, y: true, z: "A string" })
[
[
"x",
10
],
[
"y",
true
],
[
"z",
"A string"
]
]
>
entries(object("x", 10, "y", true, "z", "A string"))
[
[
"x",
10
],
[
"y",
true
],
[
"z",
"A string"
]
]
Description
Returns entry (key-value pair) for key, or null if key not present in obj.
Examples
>
{ a: 1, "b": 2 } find "a"
[
"a",
1
]
>
find(object("a", 1, "b", 2), "b")
[
"b",
2
]
>
find(object("a", 1, "b", 2), "c")
null
Description
Returns a new object created by merging together all arguments.
If two keys appears in more than one object the value from the last object is used.
If no arguments are provided null is returned.
Examples
>
{ x: 10 } merge { y: 20 }
{
"x": 10,
"y": 20
}
>
merge(object("x", 10), object("y", 20))
{
"x": 10,
"y": 20
}
>
merge(object("x", 10), object("x", 15, "y", 20))
{
"x": 15,
"y": 20
}
| merge-with(...objs, fun) |
→ |
object |
Description
Returns a new object created by merging together all arguments.
If two keys appears in more than one object
fun is used to calculate the new value.
If no arguments are provided null is returned.
Examples
>
merge-with(object("x", 10), object("y", 20), +)
{
"x": 10,
"y": 20
}
>
merge-with(object("x", 10), object("x", 15, "y", 20), +)
{
"x": 25,
"y": 20
}
>
merge-with({ x: 10 }, { x: 20 }, { x: 30 }, { x: 40 }, -)
{
"x": -80
}
Description
Returns a new object created by mapping a to b.
Examples
>
["a", "b", "c"] zipmap [1, 2, 3]
{
"a": 1,
"b": 2,
"c": 3
}
>
zipmap(["a", "b", "c"], [10, null, [1, 2, 3]])
{
"a": 10,
"b": null,
"c": [
1,
2,
3
]
}
>
zipmap(["a", "b", "c"], [1])
{
"a": 1
}
>
zipmap([], [10, null, [1, 2, 3]])
{}
Description
Returns an object containing only those entries in a whose key is in b.
Examples
>
{ a: 1, b: 2, c: 3 } select-keys ["a", "b"]
{
"a": 1,
"b": 2
}
>
select-keys({ a: 1, b: 2, c: 3 }, ["a", "b"])
{
"a": 1,
"b": 2
}
>
select-keys({ a: 1 }, ["a", "b"])
{
"a": 1
}
Description
Returns true if x is a boolean, otherwise false.
Examples
>
boolean?([1, 2, 3])
false
>
boolean?("A string")
false
Description
Returns true if x is null, otherwise false.
Examples
>
null?("A string")
false
Description
Returns true if x is a number, otherwise false.
Examples
>
number?([1, 2, 3])
false
>
number?("A string")
false
Description
Returns true if x is a string, otherwise false.
Examples
>
string?("A string")
true
>
string?(true ? "A string" : false)
true
>
string?([1, 2, 3])
false
Description
Returns true if x is a function, otherwise false.
Examples
>
function?((x, y) -> x + y)
true
>
function?("false")
false
>
function?([1, 2, 3])
false
Description
Returns true if x is an integer, otherwise false.
Examples
>
integer?((x, y) -> x + y)
false
>
integer?("false")
false
>
integer?([1, 2, 3])
false
Description
Returns true if x is an array, otherwise false.
Examples
>
array?(object("a", 10))
false
>
array?((x, y) -> x + y)
false
Description
Returns true if x is an object, otherwise false.
Examples
>
object?(object("a", 10))
true
>
object?((x, y) -> x + y)
false
>
object?(#"^start")
false
>
object?([1, 2, 3])
false
Description
Returns true if x is a Coll i.e. an array, an object or a string, otherwise false.
Examples
>
coll?(object("a", 10))
true
>
coll?((x, y) -> x + y)
false
Description
Returns true if x is a Seq i.e. an array or a string, otherwise false.
Examples
>
seq?(object("a", 10))
false
>
seq?((x, y) -> x + y)
false
Description
Returns true if x is a regexp, otherwise false.
Examples
>
regexp?(regexp("^start"))
true
>
regexp?(#"^start")
true
>
regexp?((x, y) -> x + y)
false
>
regexp?([1, 2, 3])
false
Description
Returns true if x is 0, otherwise false.
Description
Returns true if x is greater than 0, otherwise false.
Description
Returns true if x is less than 0, otherwise false.
Description
Returns true if x is even, otherwise false.
Description
Returns true if x is odd, otherwise false.
Description
Returns true if x is finite, otherwise false.
Description
Returns true if x equals negative infinity, otherwise false.
Examples
>
negative-infinity?(1.0)
false
>
negative-infinity?(1 / 0)
false
>
negative-infinity?(-1 / 0)
true
Description
Returns true if x equals positive infinity, otherwise false.
Examples
>
positive-infinity?(1.0)
false
>
positive-infinity?(1 / 0)
true
>
positive-infinity?(-1 / 0)
false
Description
Returns true if x is true, otherwise false.
Description
Returns true if x is true, otherwise false.
Description
Returns true if x is empty or null, otherwise false.
Examples
>
empty?([1, 2, 3])
false
Description
Returns false if x is empty or null, otherwise true.
Examples
>
not-empty?([1, 2, 3])
true
>
not-empty?({ a: 2 })
true
>
not-empty?("Albert")
true
Description
Checks if a value is a vector. A vector is an array of numbers.
Arguments
| value |
any |
The value to check.
|
Examples
>
vector?([1, 2, 3])
true
>
vector?([1, 2, "3"])
false
Description
Checks if a value is a matrix. A matrix is an array of arrays of numbers.
Arguments
| value |
any |
The value to check.
|
Examples
>
matrix?([1, 2, 3])
false
>
matrix?([[1, 2], [3, 4]])
true
>
matrix?([[1, 2], [3, "4"]])
false
>
matrix?([[1, 2], [3]])
false
Description
Checks if a value is a grid. A grid is an array of arrays where all inner arrays have the same length.
Arguments
| value |
any |
The value to check.
|
Examples
>
grid?(["1", 2, 3])
false
>
grid?([["1", 2], [3, 4]])
true
>
grid?([["1", 2], [3, "4"]])
true
>
grid?([["1", 2], [3]])
false
Description
Creates a RegExp from pattern and flags.
Arguments
| pattern |
string |
| flags |
string |
Optional flags for the regular expression. Possible values are the same as Javascript RegExp takes.
|
Examples
>
regexp("^\s*(.*)$")
/^s*(.*)$/
>
#"^\s*(.*)$"
/^\s*(.*)$/
>
regexp("albert", "ig")
/albert/ig
| a match b |
→ |
Array<any> |
| match(a, b) |
→ |
Array<any> |
Description
Matches b against regular expression a.
If b is a string and matches the regular expression, a match-array is returned, otherwise null is returned.
Examples
>
match(" A string", regexp("^\\s*(.*)$"))
[
" A string",
"A string"
]
>
match(" A string", #"^\s*(.*)$")
[
" A string",
"A string"
]
>
match("My name is Albert", #"albert"i)
[
"Albert"
]
>
match("My name is Ben", #"albert"i)
null
>
match(null, #"albert"i)
null
>
match(1, #"albert"i)
null
>
match({}, #"albert"i)
null
| replace(a, b, x) |
→ |
Array<any> |
Description
Returns a new string with first match of regular expression b replaced by x.
Examples
>
replace("Duck duck", "u", "i")
"Dick duck"
>
replace("Duck duck", #"u", "i")
"Dick duck"
>
replace("abcABC", regexp("a", "i"), "-")
"-bcABC"
>
replace("abcABC", regexp("a", "gi"), "-")
"-bc-BC"
>
replace("abcABC", #"a"i, "-")
"-bcABC"
>
replace("abcABC", #"a"gi, "-")
"-bc-BC"
| replace-all(a, b, x) |
→ |
Array<any> |
Description
Returns a new string with all matches of regular expression b replaced by x.
Examples
>
replace-all("Duck duck", "u", "i")
"Dick dick"
>
replace-all("Duck duck", regexp("u"), "i")
"Dick dick"
>
replace-all("abcABC", regexp("a", "i"), "-")
"-bc-BC"
>
replace-all("abcABC", regexp("a", "gi"), "-")
"-bc-BC"
>
replace-all("abcABC", #"a"i, "-")
"-bc-BC"
>
replace-all("abcABC", #"a"gi, "-")
"-bc-BC"
Description
Repeates s n times.
Examples
>
"*" string-repeat 10
"**********"
>
string-repeat("*", 10)
"**********"
>
string-repeat("***", 0)
""
Description
Concatenats values into one string. If value equals null empty string is returned.
Examples
>
str("A string", ", and another string", " ...and more")
"A string, and another string ...and more"
>
str("Just one string")
"Just one string"
>
str(0, false, true, null, #"^kalle", [1, 2, 3], {a: "a"})
"0falsetrue[object Object][1,2,3]{"a":"a"}"
Description
Parses s to a number.
Description
Returns s converted to lower case.
Examples
>
lower-case("Albert")
"albert"
Description
Returns s converted to upper case.
Examples
>
upper-case("Albert")
"ALBERT"
Description
Returns a new string with leading and trailing whitespaces removed.
Examples
>
trim(" Albert ")
"Albert"
Description
Returns a new string with leading whitespaces removed.
Examples
>
trim-left(" Albert ")
"Albert "
Description
Returns a new string with trailing whitespaces removed.
Examples
>
trim-right(" Albert ")
" Albert"
| a pad-left b |
→ |
string |
| pad-left(s, length) |
→ |
string |
| pad-left(s, length, padString) |
→ |
string |
Description
Pads from the start of s with padString (multiple times, if needed) until the resulting string reaches the given length.
Examples
>
"Albert" pad-left 20
" Albert"
>
pad-left("Albert", 20)
" Albert"
>
pad-left("Albert", 20, "-*-")
"-*--*--*--*--*Albert"
>
pad-left("Albert", 5)
"Albert"
>
pad-left("Albert", -1)
"Albert"
| a pad-right b |
→ |
string |
| pad-right(s, length) |
→ |
string |
| pad-right(s, length, padString) |
→ |
string |
Description
Pads from the start of s with padString (multiple times, if needed) until the resulting string reaches the given length.
Examples
>
"Albert" pad-right 20
"Albert "
>
pad-right("Albert", 20)
"Albert "
>
pad-right("Albert", 20, "-*-")
"Albert-*--*--*--*--*"
>
pad-right("Albert", 5)
"Albert"
>
pad-right("Albert", -1)
"Albert"
Description
Divides s into an array of substrings. The division is done by searching for delimiter. If limit as provided, at most limit number of substrings are returned.
Examples
>
"Albert Mojir" split " "
[
"Albert",
"Mojir"
]
>
split("Albert Mojir", " ")
[
"Albert",
"Mojir"
]
>
split("abcdefghijklmnopqrstuvw", #"[aoueiy]")
[
"",
"bcd",
"fgh",
"jklmn",
"pqrst",
"vw"
]
>
split("0123456789", "")
[
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
]
>
split("0123456789", "", 5) map number
[0, 1, 2, 3, 4]
Description
Divides s into an array of substrings, each representing a line.
Examples
>
split-lines("Albert
Mojir
")
[
"Albert",
"Mojir"
]
>
split-lines("Albert
Mojir")
[
"Albert",
"Mojir"
]
>
split-lines("Albert
Mojir
")
[
"Albert",
"Mojir"
]
| template(s, ...params) |
→ |
string |
Description
Applies placeholders to a string. Support for basic pluralization - see examples. If pluralization is used, first placeholder must be a number.
Examples
>
template("Hi, $1 and $2", "Carl", "Larry")
"Hi, Carl and Larry"
>
template("Hi $1, $2, $3, $4, $5, $6, $7, $8 and $9", "A", "B", "C", "D", "E", "F", "G", "H", "I")
"Hi A, B, C, D, E, F, G, H and I"
>
template("$1 book||||$1 books", 0)
"0 books"
>
template("$1 book||||$1 books", 1)
"1 book"
>
template("$1 book||||$1 books", 2)
"2 books"
>
template("No book||||$1 book||||$1 books", 0)
"No book"
>
template("No book||||$1 book||||$1 books", 1)
"1 book"
>
template("No book||||$1 book||||$1 books", 10)
"10 books"
>
template("No book||||One book||||Two books||||Three books||||$1 books", 0)
"No book"
>
template("No book||||One book||||Two books||||Three books||||$1 books", 1)
"One book"
>
template("No book||||One book||||Two books||||Three books||||$1 books", 2)
"Two books"
>
template("No book||||One book||||Two books||||Three books||||$1 books", 3)
"Three books"
>
template("No book||||One book||||Two books||||Three books||||$1 books", 4)
"4 books"
Description
Return code point for first character in c.
Examples
>
to-char-code("Albert")
65
Description
Return character for code point code.
Description
Returns a Base64 encoded string from s.
Examples
>
encode-base64("Albert")
"QWxiZXJ0"
| decode-base64(base64string) |
→ |
string |
Description
Returns a Base64 decoded string from base64string.
Examples
>
decode-base64("QWxiZXJ0IPCfkLs=")
"Albert 🐻"
| encode-uri-component(s) |
→ |
string |
Description
Returns an escaped URI string.
Examples
>
encode-uri-component("Hi everyone!?")
"Hi%20everyone!%3F"
| decode-uri-component(s) |
→ |
string |
Description
Returns an un-escaped URI string.
Examples
>
decode-uri-component("Hi%20everyone!%3F%20%F0%9F%91%8D")
"Hi everyone!? 👍"
Description
Returns a new string by concatenating all of the elements in arr, separated by delimiter.
Examples
>
map([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], str) join ", "
"0, 1, 2, 3, 4, 5, 6, 7, 8, 9"
>
([0, 1, 2, 3, 4, 5, 6, 7, 8, 9] map str) join ", "
"0, 1, 2, 3, 4, 5, 6, 7, 8, 9"
>
join(["Albert", 10], ", ")
"Albert, 10"
>
join(["Albert", "Mojir"], " ")
"Albert Mojir"
>
join(map([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], str), ", ")
"0, 1, 2, 3, 4, 5, 6, 7, 8, 9"
Description
Returns s with the first character converted to uppercase and the rest to lowercase.
Examples
>
capitalize("albert")
"Albert"
>
capitalize("ALBERT")
"Albert"
>
capitalize("aLBERT")
"Albert"
Description
Returns true if s is null or only contains whitespace characters.
| doseq (...binding) -> body |
Description
Iterates over bindings, evaluates body for each binding and returns null. This is useful for side effects.
Details
| binding |
loop-var in collection [...let-binding] [where whereExpr] [while whileExp] |
A doseq loop binding
|
| loop-var |
symbol |
The name of the loop variable.
|
| collection |
any |
The collection to iterate over.
|
| let-binding |
let binding |
A let binding to create a local variable.
|
| whereExpr |
expression |
An expression that must evaluate to truthy for the loop body to be executed.
|
| whileExp |
expression |
An expression that must evaluate to truthy for the loop to continue.
|
| body |
expressions |
The expressions to evaluate for each iteration of the loop.
|
Examples
>
doseq (i in [1, 2, 3]) -> write!(i * 2)
null
Description
Iterates over bindings, evaluates body for each binding and returns an array of results.
Details
| binding |
loop-var in collection [...let-binding] [where whereExpr] [while whileExp] |
A for loop binding
|
| loop-var |
symbol |
The name of the loop variable.
|
| collection |
any |
The collection to iterate over.
|
| let-binding |
let binding |
A let binding to create a local variable.
|
| whereExpr |
expression |
An expression that must evaluate to truthy for the loop body to be executed.
|
| whileExp |
expression |
An expression that must evaluate to truthy for the loop to continue.
|
| body |
expressions |
The expressions to evaluate for each iteration of the loop.
|
Examples
>
for (i in [1, 2, 3]) -> i * 2
[2, 4, 6]
>
for (
i in range(10) let ii = i ^ 2 while ii < 40 when ii % 3 == 0,
j in range(10) when j % 2 == 1
) -> ii + j
[
1,
3,
5,
7,
9,
10,
12,
14,
16,
18,
37,
39,
41,
43,
45
]
| a array b |
→ |
Array<any> |
| array(...values) |
→ |
Array<any> |
Description
Makes new array from values.
Examples
>
array(1, 2, 3)
[1, 2, 3]
>
array(array(null, false, true))
[ null false true ]
>
[1, 2, ...[3, 4, 5], 6]
[1, 2, 3, 4, 5, 6]
>
[[null, false, true]]
[ null false true ]
Description
Constructs a new object. Object members are created from the kvps key-value pairs. Requires an even number of arguments.
Arguments
| kvps |
Array<any> |
key - value pairs, where key is a string
|
Examples
>
let default = {
type: "Person",
name: "John Doe",
age: 42
};
{
...default,
name: "Lisa"
}
{
"type": "Person",
"name": "Lisa",
"age": 42
}
>
object("x", 10, "y", true, "z", "A string")
{
"x": 10,
"y": true,
"z": "A string"
}
>
{ a: 1, b: 2 }
{
"a": 1,
"b": 2
}
| a && b |
→ |
any |
| &&(a, b) |
→ |
any |
| &&(a, b, ...c) |
→ |
any |
Description
Computes logical
and. Evaluation of expressions starts from left.
As soon as an
expression evaluates to a falsy value, the result is returned.
If all expressions evaluate to truthy values, the value of the last expression is returned.
Examples
>
&&(3 > 2, "string")
"string"
>
&&(3 < 2, "string")
false
>
&&(true, true, true, true)
true
>
&&(true, true, 0, true)
0
Description
Computes logical
or. Evaluation of expressions evaluation starts from left.
As soon as a
expression evaluates to a truthy value, the result is returned.
If all expressions evaluate to falsy values, the value of the last expression is returned.
Examples
>
||(3 > 2, "string")
true
>
||(3 < 2, "string")
"string"
>
||(false, false, false, true)
true
Description
Binds local variables s to value. value can be any expression. The scope of the variables is the body of the let expression.
Details
| s |
symbol |
The name of the variable to bind.
|
| value |
any |
The value to bind to the variable.
|
Examples
>
let a = 1 + 2 + 3 + 4;
let b = -> $ * ( $ + 1 );
write!("a", a, "b", b)
<function λ>
| try { try-body } catch { catch-body } |
| try { try-body } catch(error) { catch-body } |
Description
Executes try-body. If that throws, the catch-body gets executed. See examples for details.
Details
| try-body |
expressions |
The expressions to try.
|
| error |
symbol |
The error variable to bind.
|
| catch-body |
expression |
The expressions to evaluate if the try-body throws an error.
|
Examples
>
try
2 / 4
catch
"Oops!"
end
0.5
>
try
foo()
catch(error)
"Error: " ++ error.message
end
"Error: Undefined symbol 'foo'."
>
try
foo()
catch
42
end
42
Description
Throws UserDefinedError with message set to expr evaluated. expr must evaluate to a string.
Examples
>
try throw("You shall not pass!") catch(error) "Error: " ++ error.message end
"Error: You shall not pass!"
>
try throw(slice("You shall not pass!", 0, 3)) catch(error) "Error: " ++ error.message end
"Error: You"
| if test then true-expr else false-expr |
| if test then true-expr |
Description
Either true-expr or false-expr branch is taken. true-expr is selected when $test is truthy. If $test is falsy false-expr is executed, if no false-expr exists, null is returned.
Details
| test |
expression |
The condition to test.
|
| true-expr |
expression |
The expression to evaluate if the test is truthy.
|
| false-expr |
expression |
The expression to evaluate if the test is falsy.
|
Examples
>
if true then
write!("TRUE")
else
write!("FALSE")
end
"TRUE"
>
if false then write!("TRUE") else write!("FALSE") end
"FALSE"
>
if true then write!("TRUE") end
"TRUE"
>
if false then write!("TRUE") end
null
| unless test then true-expr else false-expr end |
| unless test true-expr end |
Description
Either true-expr or false-expr branch is taken. true-expr is selected when $test is falsy. If $test is truthy false-expr is executed, if no false-expr exists, null is returned.
Details
| test |
expression |
The condition to test.
|
| true-expr |
expression |
The expressions to evaluate if the test is falsy.
|
| false-expr |
expression |
The expressions to evaluate if the test is truthy.
|
Examples
>
unless true then
write!("TRUE")
else
write!("FALSE")
end
"FALSE"
>
unless false then write!("TRUE") else write!("FALSE") end
"TRUE"
>
unless true then write!("TRUE") end
null
>
unless false then write!("TRUE") end
"TRUE"
| cond cond-branch cond-branch ... end |
Description
Used for branching. cond-branches are tested sequentially from the top. If no branch is tested truthy, null is returned.
Details
| cond-branch |
case test then body |
A branch of the cond expression.
|
| test |
expression |
The condition to test.
|
| body |
expressions |
The expressions to evaluate if the test is truthy.
|
Examples
>
cond
case false then write!("FALSE")
case true then write!("TRUE")
end
"TRUE"
>
cond
case false then write!("FALSE")
case null then write!("null")
end ?? write!("TRUE")
"TRUE"
>
cond
case false then write!("FALSE")
case null then write!("null")
end ?? write!("TRUE")
"TRUE"
| switch value switch-branch switch-branch ... end |
Description
Used for branching. switch-branches are tested sequentially from the top against value. If no branch is tested truthy, null is returned.
Details
| value |
any |
The value to test.
|
| switch-branch |
case test then body |
A branch of the switch expression.
|
| test |
expression |
The condition to test.
|
| body |
expressions |
The expressions to evaluate if the test is truthy.
|
Examples
>
switch 1
case 1 then write!("One")
case 2 then write!("Two")
end
"One"
>
switch 2
case 1 then write!("One")
case 2 then write!("Two")
end
"Two"
>
switch 3
case 1 then write!("One")
case 2 then write!("Two")
end
null
Description
Evaluates body. Resulting value is the value of the last expression.
Details
| body |
expressions |
The expressions to evaluate.
|
Examples
>
{
let a = 1 + 2 + 3 + 4;
let b = -> $ * ( $ + 1 );
b(a)
}
110
Description
Recursevly calls enclosing function or loop with its evaluated recur-args.
Examples
>
let foo = (n) -> {
write!(n);
if !(zero?(n)) then
recur(n - 1)
end
};
foo(3)
null
>
(n -> {
write!(n);
if !(zero?(n)) then
recur(n - 1)
end
})(3)
null
>
loop (n = 3) -> {
write!(n);
if !(zero?(n)) then
recur(n - 1)
end
}
null
Description
Shorthand for regexp(pattern). Only difference is that escaping is not needed.
Examples
>
#"^\s*(.*)$"
/^\s*(.*)$/
Description
Shorthand for
(args, ...) -> expression.
$1, $2, $3, ... are shorthand for the first, second, third, ... argument.
You can reference the first argument using either $1 or $.
However, please note that $1 and $ are mutually exclusive and cannot be used simultaneously.
E.g. #(* $ $1) is not valid.
Examples
>
-> $1 + $2
<function λ>
Description
An object, a collection of key-value pairs where keys are strings
Examples
>
{ a: 1, b: 2}
{
"a": 1,
"b": 2
}
Examples
>
["a", null, true]
[
"a",
null,
true
]
Description
An array of numbers
Description
A matrix, a two-dimensional array with numbers where each row has the same number of columns. A matrix is also a grid.
Examples
>
[[1, 2], [3, 4]]
[ 1 2 ]
[ 3 4 ]
>
[[1, 2], [3, 4], [5, 6]]
[ 1 2 ]
[ 3 4 ]
[ 5 6 ]
Description
A grid, a two-dimensional array where each row has the same number of columns
Examples
>
[[1, 2], [3, 4]]
[ 1 2 ]
[ 3 4 ]
>
[["a", "b"], [3, 4], [5, 6]]
[ a b ]
[ 3 4 ]
[ 5 6 ]
Examples
>
x -> x + 1
<function λ>
>
(a, b, c) -> (a + b) * c
<function λ>
>
-> $1 + $2
<function λ>
Description
The value null
Description
A collection, an object, an array or a string
Examples
>
{ foo: 42 }
{
"foo": 42
}
Description
A sequence, an array or a string
Description
A regular expression
Examples
>
regexp("^\\s*(.*)$")
/^\s*(.*)$/
Description
A value that can never be created
Examples
>
// throw("error") will never return a value
try throw("error") catch "never" end
"never"
let { mean } = import("Vector")
Description
Returns the mean of all elements in the vector.
Arguments
| vector |
vector |
The vector to calculate the mean of.
|
Examples
>
let { mean } = import("Vector");
mean([1, 2, 3])
2
>
let { mean } = import("Vector");
mean([1, 2, -3])
0
let { moving-mean } = import("Vector")
| Vector.moving-mean(vector, windowSize) |
→ |
vector |
Description
Returns the moving mean of the vector with a given window size.
Examples
>
let { moving-mean } = import("Vector");
moving-mean([1, 2, 3, 4, 5], 3)
[2, 3, 4]
>
let { moving-mean } = import("Vector");
moving-mean([1, 2, 3, 4, 5], 5)
[3]
let { centered-moving-mean } = import("Vector")
| Vector.centered-moving-mean(vector, windowSize) |
→ |
array |
| Vector.centered-moving-mean(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-mean(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving mean of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving mean of.
|
| windowSize |
integer |
The size of the centered moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-mean } = import("Vector");
centered-moving-mean([1, 2, 3, 4, 5], 3)
[
null,
2,
3,
4,
null
]
>
let { centered-moving-mean } = import("Vector");
centered-moving-mean([1, 2, 3, 4, 5], 3, 0, 10)
[1, 2, 3, 4, 6.333333333333333]
>
let { centered-moving-mean } = import("Vector");
centered-moving-mean([1, 2, 3, 4, 5], 3, 10)
[
4.333333333333333,
2,
3,
4,
null
]
let { running-mean } = import("Vector")
| Vector.running-mean(vector) |
→ |
vector |
Description
Returns the running mean of the vector.
Arguments
| vector |
vector |
The vector to calculate the running mean of.
|
Examples
>
let { running-mean } = import("Vector");
running-mean([1, 2, 3, 4, 5])
[1, 1.5, 2, 2.5, 3]
let { geometric-mean } = import("Vector")
| Vector.geometric-mean(vector) |
→ |
number |
Description
Returns the geometric mean of all elements in the vector.
Arguments
| vector |
vector |
The vector to calculate the geometric mean of.
|
Examples
>
let { geometric-mean } = import("Vector");
geometric-mean([1, 2, 3])
1.8171205928321394
>
let { geometric-mean } = import("Vector");
geometric-mean([1, 2, 9])
2.620741394208897
let { moving-geometric-mean } = import("Vector")
| Vector.moving-geometric-mean(vector, windowSize) |
→ |
vector |
Description
Returns the moving geometric mean of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving geometric mean of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-geometric-mean } = import("Vector");
moving-geometric-mean([1, 2, 3, 4, 5], 3)
[1.8171205928321394, 2.8844991406148166, 3.9148676411688634]
>
let { moving-geometric-mean } = import("Vector");
moving-geometric-mean([1, 2, 3, 4, 5], 5)
[2.6051710846973517]
let { centered-moving-geometric-mean } = import("Vector")
| Vector.centered-moving-geometric-mean(vector, windowSize) |
→ |
array |
| Vector.centered-moving-geometric-mean(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-geometric-mean(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving geometric mean of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving geometric mean of.
|
| windowSize |
integer |
The size of the centered moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-geometric-mean } = import("Vector");
centered-moving-geometric-mean([1, 2, 3, 4, 5], 3)
[
null,
1.8171205928321394,
2.8844991406148166,
3.9148676411688634,
null
]
>
let { centered-moving-geometric-mean } = import("Vector");
centered-moving-geometric-mean([1, 2, 3, 4, 5], 3, 0, 10)
[0, 1.8171205928321394, 2.8844991406148166, 3.9148676411688634, 5.848035476425733]
>
let { centered-moving-geometric-mean } = import("Vector");
centered-moving-geometric-mean([1, 2, 3, 4, 5], 3, 10)
[
2.7144176165949068,
1.8171205928321394,
2.8844991406148166,
3.9148676411688634,
null
]
let { running-geometric-mean } = import("Vector")
| Vector.running-geometric-mean(vector) |
→ |
vector |
Description
Returns the running geometric mean of the vector.
Arguments
| vector |
vector |
The vector to calculate the running geometric mean of.
|
Examples
>
let { running-geometric-mean } = import("Vector");
running-geometric-mean([1, 2, 3, 4, 5])
[1, 1.414213562373095, 1.8171205928321394, 2.213363839400643, 2.6051710846973517]
let { harmonic-mean } = import("Vector")
| Vector.harmonic-mean(vector) |
→ |
number |
Description
Returns the harmonic mean of all elements in the vector.
Arguments
| vector |
vector |
The vector to calculate the harmonic mean of.
|
Examples
>
let { harmonic-mean } = import("Vector");
harmonic-mean([1, 2, 3])
1.6363636363636365
>
let { harmonic-mean } = import("Vector");
harmonic-mean([1, 2, 9])
1.8620689655172413
let { moving-harmonic-mean } = import("Vector")
| Vector.moving-harmonic-mean(vector, windowSize) |
→ |
vector |
Description
Returns the moving harmonic mean of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving harmonic mean of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-harmonic-mean } = import("Vector");
moving-harmonic-mean([1, 2, 3, 4, 5], 3)
[1.6363636363636365, 2.7692307692307696, 3.829787234042554]
>
let { moving-harmonic-mean } = import("Vector");
moving-harmonic-mean([1, 2, 3, 4, 5], 5)
[2.18978102189781]
let { centered-moving-harmonic-mean } = import("Vector")
| Vector.centered-moving-harmonic-mean(vector, windowSize) |
→ |
array |
| Vector.centered-moving-harmonic-mean(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-harmonic-mean(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving harmonic mean of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving harmonic mean of.
|
| windowSize |
integer |
The size of the centered moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-harmonic-mean } = import("Vector");
centered-moving-harmonic-mean([1, 2, 3, 4, 5], 3)
[
null,
1.6363636363636365,
2.7692307692307696,
3.829787234042554,
null
]
>
let { centered-moving-harmonic-mean } = import("Vector");
centered-moving-harmonic-mean([1, 2, 3, 4, 5], 3, 0, 10)
[0, 1.6363636363636365, 2.7692307692307696, 3.829787234042554, 5.454545454545454]
>
let { centered-moving-harmonic-mean } = import("Vector");
centered-moving-harmonic-mean([1, 2, 3, 4, 5], 3, 10)
[
1.875,
1.6363636363636365,
2.7692307692307696,
3.829787234042554,
null
]
let { running-harmonic-mean } = import("Vector")
| Vector.running-harmonic-mean(vector) |
→ |
vector |
Description
Returns the running harmonic mean of the vector.
Arguments
| vector |
vector |
The vector to calculate the running harmonic mean of.
|
Examples
>
let { running-harmonic-mean } = import("Vector");
running-harmonic-mean([1, 2, 3, 4, 5])
[1, 1.3333333333333333, 1.6363636363636365, 1.9200000000000004, 2.18978102189781]
let { median } = import("Vector")
| Vector.median(vector) |
→ |
number |
Description
Returns the median of all elements in the vector.
Arguments
| vector |
vector |
The vector to calculate the median of.
|
Examples
>
let { median } = import("Vector");
median([1, 2, 3])
2
>
let { median } = import("Vector");
median([1, 2, -3])
1
>
let { median } = import("Vector");
median([1, 2, 3, 4])
2.5
>
let { median } = import("Vector");
median([1, 2, -3, 4])
1.5
let { moving-median } = import("Vector")
| Vector.moving-median(vector, windowSize) |
→ |
vector |
Description
Returns the moving median of the vector with a given window size.
Examples
>
let { moving-median } = import("Vector");
moving-median([1, 2, 3, 4, 5], 3)
[2, 3, 4]
>
let { moving-median } = import("Vector");
moving-median([1, 2, 3, 4, 5], 5)
[3]
let { centered-moving-median } = import("Vector")
| Vector.centered-moving-median(vector, windowSize) |
→ |
array |
| Vector.centered-moving-median(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-median(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving median of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving median of.
|
| windowSize |
integer |
The size of the centered moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-median } = import("Vector");
centered-moving-median([1, 2, 3, 4, 5], 3)
[
null,
2,
3,
4,
null
]
>
let { centered-moving-median } = import("Vector");
centered-moving-median([1, 2, 3, 4, 5], 3, 0, 10)
[1, 2, 3, 4, 5]
>
let { centered-moving-median } = import("Vector");
centered-moving-median([1, 2, 3, 4, 5], 3, 10)
[
2,
2,
3,
4,
null
]
let { running-median } = import("Vector")
| Vector.running-median(vector) |
→ |
vector |
Description
Returns the running median of the vector.
Arguments
| vector |
vector |
The vector to calculate the running median of.
|
Examples
>
let { running-median } = import("Vector");
running-median([1, 2, 3, 4, 5])
[1, 1.5, 2, 2.5, 3]
let { variance } = import("Vector")
| Vector.variance(vector) |
→ |
number |
Description
Returns the variance of all elements in the vector.
Arguments
| vector |
vector |
The vector to calculate the variance of.
|
Examples
>
let { variance } = import("Vector");
variance([1, 2, 3])
0.6666666666666666
>
let { variance } = import("Vector");
variance([1, 2, -3])
4.666666666666667
let { moving-variance } = import("Vector")
| Vector.moving-variance(vector, windowSize) |
→ |
vector |
Description
Returns the moving variance of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving variance of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-variance } = import("Vector");
moving-variance([1, 2, 3, 4, 5], 3)
[0.6666666666666666, 0.6666666666666666, 0.6666666666666666]
>
let { moving-variance } = import("Vector");
moving-variance([1, 2, 3, 4, 5], 5)
[2]
let { centered-moving-variance } = import("Vector")
| Vector.centered-moving-variance(vector, windowSize) |
→ |
array |
| Vector.centered-moving-variance(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-variance(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving variance of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving variance of.
|
| windowSize |
integer |
The size of the centered moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-variance } = import("Vector");
centered-moving-variance([1, 2, 3, 4, 5], 3)
[
null,
0.6666666666666666,
0.6666666666666666,
0.6666666666666666,
null
]
>
let { centered-moving-variance } = import("Vector");
centered-moving-variance([1, 2, 3, 4, 5], 3, 1)
[
0.2222222222222222,
0.6666666666666666,
0.6666666666666666,
0.6666666666666666,
null
]
>
let { centered-moving-variance } = import("Vector");
centered-moving-variance([1, 2, 3, 4, 5], 3, 1, 5)
[0.2222222222222222, 0.6666666666666666, 0.6666666666666666, 0.6666666666666666, 0.22222222222222224]
>
let { centered-moving-variance } = import("Vector");
centered-moving-variance([1, 2, 3, 4, 5], 3, 0, 6)
[0.6666666666666666, 0.6666666666666666, 0.6666666666666666, 0.6666666666666666, 0.6666666666666666]
let { running-variance } = import("Vector")
| Vector.running-variance(vector) |
→ |
vector |
Description
Returns the running variance of the vector.
Arguments
| vector |
vector |
The vector to calculate the running variance of.
|
Examples
>
let { running-variance } = import("Vector");
running-variance([1, 2, 3, 4, 5])
[0, 0.25, 0.6666666666666666, 1.25, 2]
let { sample-variance } = import("Vector")
| Vector.sample-variance(vector) |
→ |
number |
Description
Returns the sample variance of all elements in the vector.
Arguments
| vector |
vector |
Non emtpy vector to calculate the sample variance of.
|
Examples
>
let { sample-variance } = import("Vector");
sample-variance([1, 2, 3])
1
>
let { sample-variance } = import("Vector");
sample-variance([1, 2, -3])
7
>
let { sample-variance } = import("Vector");
sample-variance([1, 2, 3, 4])
1.6666666666666667
>
let { sample-variance } = import("Vector");
sample-variance([1, 2, -3, 4])
8.666666666666666
>
let { sample-variance } = import("Vector");
sample-variance([1, 2, 3, 40, 50])
567.7
let { moving-sample-variance } = import("Vector")
| Vector.moving-sample-variance(vector, windowSize) |
→ |
vector |
Description
Returns the moving sample variance of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving sample variance of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-sample-variance } = import("Vector");
moving-sample-variance([1, 2, 3, 4, 5], 3)
[1, 1, 1]
>
let { moving-sample-variance } = import("Vector");
moving-sample-variance([1, 2, 3, 4, 5], 5)
[2.5]
let { centered-moving-sample-variance } = import("Vector")
| Vector.centered-moving-sample-variance(vector, windowSize) |
→ |
array |
| Vector.centered-moving-sample-variance(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-sample-variance(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving sample variance of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving sample variance of.
|
| windowSize |
integer |
The size of the centered moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-sample-variance } = import("Vector");
centered-moving-sample-variance([1, 2, 3, 4, 5], 3)
[
null,
1,
1,
1,
null
]
>
let { centered-moving-sample-variance } = import("Vector");
centered-moving-sample-variance([1, 2, 3, 4, 5], 3, 1)
[
0.3333333333333333,
1,
1,
1,
null
]
>
let { centered-moving-sample-variance } = import("Vector");
centered-moving-sample-variance([1, 2, 3, 4, 5], 3, 1, 5)
[0.3333333333333333, 1, 1, 1, 0.33333333333333337]
>
let { centered-moving-sample-variance } = import("Vector");
centered-moving-sample-variance([1, 2, 3, 4, 5], 3, 0, 6)
[1, 1, 1, 1, 1]
let { running-sample-variance } = import("Vector")
| Vector.running-sample-variance(vector) |
→ |
array |
Description
Returns the running sample variance of the vector.
Arguments
| vector |
vector |
The vector to calculate the running sample variance of. First element in result is null since sample variance is not defined for a single element.
|
Examples
>
let { running-sample-variance } = import("Vector");
running-sample-variance([1, 2, 3, 4, 5])
[
null,
0.5,
1,
1.6666666666666667,
2.5
]
let { stdev } = import("Vector")
Description
Returns the standard deviation of all elements in the vector.
Arguments
| vector |
vector |
Non emtpy vector to calculate the standard deviation of.
|
Examples
>
let { stdev } = import("Vector");
stdev([1, 2, 3])
0.816496580927726
>
let { stdev } = import("Vector");
stdev([1, 2, -3])
2.160246899469287
>
let { stdev } = import("Vector");
stdev([1, 2, 3, 4])
1.118033988749895
>
let { stdev } = import("Vector");
stdev([1, 2, -3, 4])
2.5495097567963922
>
let { stdev } = import("Vector");
stdev([1, 2, 3, 40, 50])
21.311030007955974
let { moving-stdev } = import("Vector")
| Vector.moving-stdev(vector, windowSize) |
→ |
vector |
Description
Returns the moving standard deviation of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving standard deviation of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-stdev } = import("Vector");
moving-stdev([1, 2, 3, 4, 5], 3)
[0.816496580927726, 0.816496580927726, 0.816496580927726]
>
let { moving-stdev } = import("Vector");
moving-stdev([1, 2, 3, 4, 5], 5)
[1.4142135623730951]
let { centered-moving-stdev } = import("Vector")
| Vector.centered-moving-stdev(vector, windowSize) |
→ |
array |
| Vector.centered-moving-stdev(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-stdev(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving standard deviation of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving standard deviation of.
|
| windowSize |
integer |
The size of the centered moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-stdev } = import("Vector");
centered-moving-stdev([1, 2, 3, 4, 5], 3)
[
null,
0.816496580927726,
0.816496580927726,
0.816496580927726,
null
]
>
let { centered-moving-stdev } = import("Vector");
centered-moving-stdev([1, 2, 3, 4, 5], 3, 1)
[
0.4714045207910317,
0.816496580927726,
0.816496580927726,
0.816496580927726,
null
]
>
let { centered-moving-stdev } = import("Vector");
centered-moving-stdev([1, 2, 3, 4, 5], 3, 1, 5)
[0.4714045207910317, 0.816496580927726, 0.816496580927726, 0.816496580927726, 0.4714045207910317]
>
let { centered-moving-stdev } = import("Vector");
centered-moving-stdev([1, 2, 3, 4, 5], 3, 0, 6)
[0.816496580927726, 0.816496580927726, 0.816496580927726, 0.816496580927726, 0.816496580927726]
let { running-stdev } = import("Vector")
| Vector.running-stdev(vector) |
→ |
vector |
Description
Returns the running standard deviation of the vector.
Arguments
| vector |
vector |
The vector to calculate the running standard deviation of.
|
Examples
>
let { running-stdev } = import("Vector");
running-stdev([1, 2, 3, 4, 5])
[0, 0.5, 0.816496580927726, 1.118033988749895, 1.4142135623730951]
let { sample-stdev } = import("Vector")
| Vector.sample-stdev(vector) |
→ |
number |
Description
Returns the sample standard deviation of all elements in the vector.
Arguments
| vector |
vector |
Non emtpy vector to calculate the sample standard deviation of.
|
Examples
>
let { sample-stdev } = import("Vector");
sample-stdev([1, 2, 3])
1
>
let { sample-stdev } = import("Vector");
sample-stdev([1, 2, -3])
2.6457513110645907
>
let { sample-stdev } = import("Vector");
sample-stdev([1, 2, 3, 4])
1.2909944487358056
>
let { sample-stdev } = import("Vector");
sample-stdev([1, 2, -3, 4])
2.943920288775949
>
let { sample-stdev } = import("Vector");
sample-stdev([1, 2, 3, 40, 50])
23.82645588416372
let { moving-sample-stdev } = import("Vector")
| Vector.moving-sample-stdev(vector, windowSize) |
→ |
vector |
Description
Returns the moving sample standard deviation of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving sample standard deviation of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-sample-stdev } = import("Vector");
moving-sample-stdev([1, 2, 3, 4, 5], 3)
[1, 1, 1]
>
let { moving-sample-stdev } = import("Vector");
moving-sample-stdev([1, 2, 3, 4, 5], 5)
[1.5811388300841898]
let { centered-moving-sample-stdev } = import("Vector")
| Vector.centered-moving-sample-stdev(vector, windowSize) |
→ |
array |
| Vector.centered-moving-sample-stdev(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-sample-stdev(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving sample standard deviation of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving sample standard deviation of.
|
| windowSize |
integer |
The size of the centered moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-sample-stdev } = import("Vector");
centered-moving-sample-stdev([1, 2, 3, 4, 5], 3)
[
null,
1,
1,
1,
null
]
>
let { centered-moving-sample-stdev } = import("Vector");
centered-moving-sample-stdev([1, 2, 3, 4, 5], 3, 1)
[
0.5773502691896257,
1,
1,
1,
null
]
>
let { centered-moving-sample-stdev } = import("Vector");
centered-moving-sample-stdev([1, 2, 3, 4, 5], 3, 1, 5)
[0.5773502691896257, 1, 1, 1, 0.5773502691896258]
>
let { centered-moving-sample-stdev } = import("Vector");
centered-moving-sample-stdev([1, 2, 3, 4, 5], 3, 0, 6)
[1, 1, 1, 1, 1]
let { running-sample-stdev } = import("Vector")
| Vector.running-sample-stdev(vector) |
→ |
array |
Description
Returns the running sample standard deviation of the vector.
Arguments
| vector |
vector |
The vector to calculate the running sample standard deviation of. First element in result is null since sample standard deviation is not defined for a single element.
|
Examples
>
let { running-sample-stdev } = import("Vector");
running-sample-stdev([1, 2, 3, 4, 5])
[
null,
0.7071067811865476,
1,
1.2909944487358056,
1.5811388300841898
]
let { iqr } = import("Vector")
Description
Calculates the interquartile range of a vector. Returns the difference between the third and first quartiles.
Arguments
| vector |
vector |
The vector to calculate the interquartile range of. Minimum length is 4.
|
Examples
>
let { iqr } = import("Vector");
iqr([1, 2, 3, 4])
2
>
let { iqr } = import("Vector");
iqr([5, 4, 3, 2, 1, 2, 3, 4, 5])
2.5
>
let { iqr } = import("Vector");
iqr(range(1, 1000))
500
>
let { iqr, generate } = import("Vector");
iqr(generate(1000, -> 1e6 / ($ + 1) ^ 2))
14.160969822456888
>
let { iqr, generate } = import("Vector");
iqr(generate(1000, -> ln($ + 1)))
1.0972825006502305
let { moving-iqr } = import("Vector")
| Vector.moving-iqr(vector, windowSize) |
→ |
vector |
Description
Calculates the moving interquartile range of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving interquartile range of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-iqr } = import("Vector");
moving-iqr([1, 2, 4, 7, 11, 16], 4)
[4, 6, 8]
>
let { moving-iqr } = import("Vector");
moving-iqr([1, 2, 4, 7, 11, 16], 5)
[7.5, 10.5]
>
let { moving-iqr } = import("Vector");
moving-iqr([1, 2, 4, 7, 11, 16], 6)
[9]
let { centered-moving-iqr } = import("Vector")
| Vector.centered-moving-iqr(vector, windowSize) |
→ |
array |
| Vector.centered-moving-iqr(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-iqr(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Calculates the centered moving interquartile range of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving interquartile range of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-iqr } = import("Vector");
centered-moving-iqr([1, 2, 4, 7, 11, 16], 4)
[
null,
null,
4,
6,
8,
null
]
>
let { centered-moving-iqr } = import("Vector");
centered-moving-iqr([1, 2, 4, 7, 11, 16], 4, 0, 0)
[1.5, 2.5, 4, 6, 8, 10]
let { running-iqr } = import("Vector")
| Vector.running-iqr(vector) |
→ |
vector |
Description
Calculates the running interquartile range of a vector. First three element in result is null since running interquartile range is not defined for less than four elements.
Arguments
| vector |
vector |
The vector to calculate the running interquartile range of.
|
Examples
>
let { running-iqr } = import("Vector");
running-iqr([1, 2, 3, 4, 5, 6])
[
null,
null,
null,
2,
3,
3
]
>
let { running-iqr } = import("Vector");
running-iqr([-1, -2, -3, 1, 2, 3])
[
null,
null,
null,
2.5,
4,
4
]
let { sum } = import("Vector")
Description
Returns the sum of all elements in the vector.
Arguments
| vector |
vector |
The vector to sum.
|
Examples
>
let { sum } = import("Vector");
sum([1, 2, 3])
6
>
let { sum } = import("Vector");
sum([1, 2, -3])
0
let { moving-sum } = import("Vector")
| Vector.moving-sum(vector, windowSize) |
→ |
vector |
Description
Returns the moving sum of the vector with a given window size.
Examples
>
let { moving-sum } = import("Vector");
moving-sum([1, 2, 3, 4, 5], 3)
[6, 9, 12]
>
let { moving-sum } = import("Vector");
moving-sum([1, 2, 3, 4, 5], 5)
[15]
let { centered-moving-sum } = import("Vector")
| Vector.centered-moving-sum(vector, windowSize) |
→ |
array |
| Vector.centered-moving-sum(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-sum(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving sum of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving sum of.
|
| windowSize |
integer |
The size of the centered moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-sum } = import("Vector");
centered-moving-sum([1, 2, 3, 4, 5], 3)
[
null,
6,
9,
12,
null
]
>
let { centered-moving-sum } = import("Vector");
centered-moving-sum([1, 2, 3, 4, 5], 3, 0, 0)
[3, 6, 9, 12, 9]
>
let { centered-moving-sum } = import("Vector");
centered-moving-sum([1, 2, 3, 4, 5], 3, 10)
[
13,
6,
9,
12,
null
]
let { running-sum } = import("Vector")
| Vector.running-sum(vector) |
→ |
vector |
Description
Returns the running sum of the vector.
Arguments
| vector |
vector |
The vector to calculate the running sum of.
|
Examples
>
let { running-sum } = import("Vector");
running-sum([1, 2, 3])
[1, 3, 6]
>
let { running-sum } = import("Vector");
running-sum([1, -2, -3])
[1, -1, -4]
let { prod } = import("Vector")
Description
Returns the product of all elements in the vector.
Arguments
| vector |
vector |
The vector to calculate the product of.
|
Examples
>
let { prod } = import("Vector");
prod([1, 2, 3])
6
>
let { prod } = import("Vector");
prod([1, 2, -3])
-6
let { moving-prod } = import("Vector")
| Vector.moving-prod(vector, windowSize) |
→ |
vector |
Description
Returns the moving product of the vector with a given window size.
Examples
>
let { moving-prod } = import("Vector");
moving-prod([1, 2, 3, 4, 5], 3)
[6, 24, 60]
>
let { moving-prod } = import("Vector");
moving-prod([1, 2, 3, 4, 5], 5)
[120]
let { centered-moving-prod } = import("Vector")
| Vector.centered-moving-prod(vector, windowSize) |
→ |
array |
| Vector.centered-moving-prod(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-prod(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving product of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving product of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-prod } = import("Vector");
centered-moving-prod([1, 2, 3, 4, 5], 3)
[2, 6, 24, 60, 20]
>
let { centered-moving-prod } = import("Vector");
centered-moving-prod([1, 2, 3, 4, 5], 3, 0, 0)
[0, 6, 24, 60, 0]
let { running-prod } = import("Vector")
| Vector.running-prod(vector) |
→ |
vector |
Description
Returns the running product of the vector.
Arguments
| vector |
vector |
The vector to calculate the running product of.
|
Examples
>
let { running-prod } = import("Vector");
running-prod([1, 2, 3, 4, 5])
[1, 2, 6, 24, 120]
>
let { running-prod } = import("Vector");
running-prod([1, -2, -3])
[1, -2, 6]
let { min } = import("Vector")
Description
Returns the minimum value of all elements in the vector.
Arguments
| vector |
vector |
Non emtpy vector to calculate the minimum of.
|
Examples
>
// Using "as" alias because "min" shadows a builtin function
let { min as vec-min } = import("Vector");
vec-min([1, 2, 3])
1
>
// Using "as" alias because "min" shadows a builtin function
let { min as vec-min } = import("Vector");
vec-min([1, 1, 2, 3, 3])
1
>
// Using "as" alias because "min" shadows a builtin function
let { min as vec-min } = import("Vector");
vec-min([1, 2, -3])
-3
>
// Using "as" alias because "min" shadows a builtin function
let { min as vec-min } = import("Vector");
vec-min([1, 2, 3, 4])
1
>
// Using "as" alias because "min" shadows a builtin function
let { min as vec-min } = import("Vector");
vec-min([1, 2, -3, 4])
-3
let { moving-min } = import("Vector")
| Vector.moving-min(vector, windowSize) |
→ |
vector |
Description
Returns the moving minimum of the vector with a given window size.
Examples
>
let { moving-min } = import("Vector");
moving-min([1, 2, 3, 4, 5], 3)
[1, 2, 3]
>
let { moving-min } = import("Vector");
moving-min([1, 2, 3, 4, 5], 5)
[1]
let { centered-moving-min } = import("Vector")
| Vector.centered-moving-min(vector, windowSize) |
→ |
array |
| Vector.centered-moving-min(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-min(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving minimum of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving minimum of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-min } = import("Vector");
centered-moving-min([1, 2, 3, 4, 5], 3)
[1, 1, 2, 3, 4]
>
let { centered-moving-min } = import("Vector");
centered-moving-min([1, 2, 3, 4, 5], 3, 0, 100)
[0, 1, 2, 3, 4]
>
let { centered-moving-min } = import("Vector");
centered-moving-min([1, 2, 3, 4, 5], 3, 0)
[0, 1, 2, 3, 4]
let { running-min } = import("Vector")
| Vector.running-min(vector) |
→ |
vector |
Description
Returns the running minimum of the vector.
Arguments
| vector |
vector |
The vector to calculate the running minimum of.
|
Examples
>
let { running-min } = import("Vector");
running-min([1, 2, 3])
[1, 1, 1]
>
let { running-min } = import("Vector");
running-min([1, -2, -3])
[1, -2, -3]
let { max } = import("Vector")
Description
Returns the maximum value of all elements in the vector.
Arguments
| vector |
vector |
Non emtpy vector to calculate the maximum of.
|
Examples
>
// Using "as" alias because "max" shadows a builtin function
let { max as vec-max } = import("Vector");
vec-max([1, 2, 3])
3
>
// Using "as" alias because "max" shadows a builtin function
let { max as vec-max } = import("Vector");
vec-max([1, 1, 2, 3, 3])
3
>
// Using "as" alias because "max" shadows a builtin function
let { max as vec-max } = import("Vector");
vec-max([1, 2, -3])
2
>
// Using "as" alias because "max" shadows a builtin function
let { max as vec-max } = import("Vector");
vec-max([1, 2, 3, 4])
4
>
// Using "as" alias because "max" shadows a builtin function
let { max as vec-max } = import("Vector");
vec-max([1, 2, -3, 4])
4
let { moving-max } = import("Vector")
| Vector.moving-max(vector, windowSize) |
→ |
vector |
Description
Returns the moving maximum of the vector with a given window size.
Examples
>
let { moving-max } = import("Vector");
moving-max([1, 2, 3, 4, 5], 3)
[3, 4, 5]
>
let { moving-max } = import("Vector");
moving-max([1, 2, 3, 4, 5], 5)
[5]
let { centered-moving-max } = import("Vector")
| Vector.centered-moving-max(vector, windowSize) |
→ |
array |
| Vector.centered-moving-max(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-max(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving maximum of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving maximum of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-max } = import("Vector");
centered-moving-max([1, 2, 3, 4, 5], 3)
[2, 3, 4, 5, 5]
>
let { centered-moving-max } = import("Vector");
centered-moving-max([1, 2, 3, 4, 5], 3, 0, 100)
[2, 3, 4, 5, 100]
>
let { centered-moving-max } = import("Vector");
centered-moving-max([1, 2, 3, 4, 5], 3, 0)
[2, 3, 4, 5, 5]
let { running-max } = import("Vector")
| Vector.running-max(vector) |
→ |
vector |
Description
Returns the running maximum of the vector.
Arguments
| vector |
vector |
The vector to calculate the running maximum of.
|
Examples
>
let { running-max } = import("Vector");
running-max([1, 2, 3])
[1, 2, 3]
>
let { running-max } = import("Vector");
running-max([1, -2, -3])
[1, 1, 1]
let { span } = import("Vector")
Description
Returns the difference between the maximum and minimum values in a vector.
Arguments
| vector |
vector |
The vector to calculate the span of.
|
Examples
>
let { span } = import("Vector");
span([1, 2, 3])
2
>
let { span } = import("Vector");
span([1, 1, 2, 3, 3])
2
>
let { span } = import("Vector");
span([1, 2, -3])
5
let { moving-span } = import("Vector")
| Vector.moving-span(vector, windowSize) |
→ |
vector |
Description
Calculates the moving span of a vector with a given window size.
Examples
>
let { moving-span } = import("Vector");
moving-span([1, 2, 4, 7, 11, 16], 4)
[6, 9, 12]
>
let { moving-span } = import("Vector");
moving-span([1, 2, 4, 7, 11, 16], 5)
[10, 14]
>
let { moving-span } = import("Vector");
moving-span([1, 2, 4, 7, 11, 16], 6)
[15]
let { centered-moving-span } = import("Vector")
| Vector.centered-moving-span(vector, windowSize) |
→ |
array |
| Vector.centered-moving-span(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-span(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Calculates the centered moving span of a vector with a given window size. The result is padded with leftPadding on the left and right.
Arguments
| vector |
vector |
The vector to calculate the centered moving span of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
The value to pad the result with on the left.
|
| rightPadding |
number |
The value to pad the result with on the right.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-span } = import("Vector");
centered-moving-span([1, 2, 4, 7, 11, 16], 4)
[
null,
null,
6,
9,
12,
null
]
>
let { centered-moving-span } = import("Vector");
centered-moving-span([1, 2, 4, 7, 11, 16], 3, 0, 100)
[2, 3, 5, 7, 9, 89]
let { running-span } = import("Vector")
| Vector.running-span(vector) |
→ |
vector |
Description
Calculates the running span of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the running span of.
|
Examples
>
let { running-span } = import("Vector");
running-span([1, 2, 4])
[0, 1, 3]
let { skewness } = import("Vector")
| Vector.skewness(vector) |
→ |
number |
Description
Calculates the skewness of a vector. Returns the third standardized moment.
Arguments
| vector |
vector |
The vector to calculate the skewness of. Minimum length is 3.
|
Examples
>
let { skewness } = import("Vector");
skewness([1, 2, 3, 6, 20])
1.3007043518904529
>
let { skewness } = import("Vector");
skewness([1, 2, 2, 3])
0
let { moving-skewness } = import("Vector")
| Vector.moving-skewness(vector, windowSize) |
→ |
vector |
Description
Calculates the moving skewness of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving skewness of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-skewness } = import("Vector");
moving-skewness([1, 2, 4, 7, 11, 16], 4)
[0.4987837491108398, 0.3461680709723672, 0.26337448559670784]
>
let { moving-skewness } = import("Vector");
moving-skewness([1, 2, 4, 7, 11, 16], 5)
[0.5504818825631803, 0.40789547778872154]
let { centered-moving-skewness } = import("Vector")
| Vector.centered-moving-skewness(vector, windowSize) |
→ |
array |
| Vector.centered-moving-skewness(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-skewness(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Calculates the centered moving skewness of a vector with a given window size and padding.
Arguments
| vector |
vector |
The vector to calculate the centered moving skewness of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-skewness } = import("Vector");
centered-moving-skewness([1, 2, 4, 7, 11, 16], 4)
[
null,
null,
0.4987837491108398,
0.3461680709723672,
0.26337448559670784,
null
]
>
let { centered-moving-skewness } = import("Vector");
centered-moving-skewness([1, 2, 4, 7, 11, 16], 4, 0, 0)
[0.49338220021815865, 0.4346507595746656, 0.4987837491108398, 0.3461680709723672, 0.26337448559670784, -0.22450274217374738]
let { running-skewness } = import("Vector")
| Vector.running-skewness(vector) |
→ |
array |
Description
Calculates the running skewness of a vector with a given window size. First two element in result is null since running skewness is not defined for less than three elements.
Arguments
| vector |
vector |
The vector to calculate the running skewness of.
|
Examples
>
let { running-skewness } = import("Vector");
running-skewness([1, 2, 4, 7, 11])
[
null,
null,
0.38180177416060584,
0.4987837491108398,
0.5504818825631803
]
let { sample-skewness } = import("Vector")
| Vector.sample-skewness(vector) |
→ |
number |
Description
Calculates the sample skewness of a vector. Returns the third standardized moment.
Arguments
| vector |
vector |
The vector to calculate the sample skewness of. Minimum length is 3.
|
Examples
>
let { sample-skewness } = import("Vector");
sample-skewness([1, 2, 3, 6, 20])
1.9389755663045736
>
let { sample-skewness } = import("Vector");
sample-skewness([1, 2, 2, 3])
0
let { moving-sample-skewness } = import("Vector")
| Vector.moving-sample-skewness(vector, windowSize) |
→ |
vector |
Description
Calculates the moving sample skewness of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving sample skewness of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-sample-skewness } = import("Vector");
moving-sample-skewness([1, 2, 4, 7, 11, 16], 4)
[0.8639187954496621, 0.5995806868822491, 0.4561779904708154]
>
let { moving-sample-skewness } = import("Vector");
moving-sample-skewness([1, 2, 4, 7, 11, 16], 5)
[0.8206099398622181, 0.6080546773668913]
let { centered-moving-sample-skewness } = import("Vector")
| Vector.centered-moving-sample-skewness(vector, windowSize) |
→ |
array |
| Vector.centered-moving-sample-skewness(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-sample-skewness(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Calculates the centered moving sample skewness of a vector with a given window size and padding.
Arguments
| vector |
vector |
The vector to calculate the centered moving sample skewness of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-sample-skewness } = import("Vector");
centered-moving-sample-skewness([1, 2, 4, 7, 11, 16], 4)
[
null,
null,
0.8639187954496621,
0.5995806868822491,
0.4561779904708154,
null
]
>
let { centered-moving-sample-skewness } = import("Vector");
centered-moving-sample-skewness([1, 2, 4, 7, 11, 16], 3, 0, 100)
[0, 0.9352195295828237, 0.585582726281389, 0.42327316026800715, 0.3308318147058979, 1.7125881376221412]
let { running-sample-skewness } = import("Vector")
| Vector.running-sample-skewness(vector) |
→ |
array |
Description
Calculates the running sample skewness of a vector with a given window size. First two element in result is null since running sample skewness is not defined for less than three elements.
Arguments
| vector |
vector |
The vector to calculate the running sample skewness of.
|
Examples
>
let { running-sample-skewness } = import("Vector");
running-sample-skewness([1, 2, 4, 7, 11])
[
null,
null,
0.9352195295828237,
0.8639187954496621,
0.8206099398622181
]
let { excess-kurtosis } = import("Vector")
| Vector.excess-kurtosis(vector) |
→ |
number |
Description
Calculates the excess kurtosis of a vector. Returns the third standardized moment.
Arguments
| vector |
vector |
The vector to calculate the excess kurtosis of. Minimum length is 3.
|
Examples
>
let { excess-kurtosis } = import("Vector");
excess-kurtosis([1, 2, 3, 6, 20])
-0.041984570307822544
>
let { excess-kurtosis } = import("Vector");
excess-kurtosis([1, 2, 2, 3])
-1.0000000000000004
let { moving-excess-kurtosis } = import("Vector")
| Vector.moving-excess-kurtosis(vector, windowSize) |
→ |
vector |
Description
Calculates the moving excess kurtosis of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving excess kurtosis of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-excess-kurtosis } = import("Vector");
moving-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)
[-1.238095238095238, -1.3024574669187146, -1.3269318701417467]
>
let { moving-excess-kurtosis } = import("Vector");
moving-excess-kurtosis([1, 2, 4, 7, 11, 16], 5)
[-1.106060606060606, -1.1953892668178383]
let { centered-moving-excess-kurtosis } = import("Vector")
| Vector.centered-moving-excess-kurtosis(vector, windowSize) |
→ |
array |
| Vector.centered-moving-excess-kurtosis(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-excess-kurtosis(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Calculates the centered moving excess kurtosis of a vector with a given window size and padding.
Arguments
| vector |
vector |
The vector to calculate the centered moving excess kurtosis of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-excess-kurtosis } = import("Vector");
centered-moving-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)
[
null,
null,
-1.238095238095238,
-1.3024574669187146,
-1.3269318701417467,
null
]
>
let { centered-moving-excess-kurtosis } = import("Vector");
centered-moving-excess-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 0)
[-1.371900826446281, -1.1542857142857144, -1.238095238095238, -1.3024574669187146, -1.3269318701417467, -1.2037934892642126]
let { running-excess-kurtosis } = import("Vector")
| Vector.running-excess-kurtosis(vector) |
→ |
array |
Description
Calculates the running excess kurtosis of a vector with a given window size. First two element in result is null since running excess kurtosis is not defined for less than three elements.
Arguments
| vector |
vector |
The vector to calculate the running excess kurtosis of.
|
Examples
>
let { running-excess-kurtosis } = import("Vector");
running-excess-kurtosis([1, 2, 4, 7, 11])
[
null,
null,
null,
-1.238095238095238,
-1.106060606060606
]
let { kurtosis } = import("Vector")
| Vector.kurtosis(vector) |
→ |
number |
Description
Calculates the kurtosis of a vector. Returns the third standardized moment.
Arguments
| vector |
vector |
The vector to calculate the kurtosis of. Minimum length is 3.
|
Examples
>
let { kurtosis } = import("Vector");
kurtosis([1, 2, 3, 6, 20])
2.9580154296921775
>
let { kurtosis } = import("Vector");
kurtosis([1, 2, 2, 3])
1.9999999999999996
let { moving-kurtosis } = import("Vector")
| Vector.moving-kurtosis(vector, windowSize) |
→ |
vector |
Description
Calculates the moving kurtosis of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving kurtosis of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-kurtosis } = import("Vector");
moving-kurtosis([1, 2, 4, 7, 11, 16], 4)
[1.761904761904762, 1.6975425330812854, 1.6730681298582533]
>
let { moving-kurtosis } = import("Vector");
moving-kurtosis([1, 2, 4, 7, 11, 16], 5)
[1.893939393939394, 1.8046107331821617]
let { centered-moving-kurtosis } = import("Vector")
| Vector.centered-moving-kurtosis(vector, windowSize) |
→ |
array |
| Vector.centered-moving-kurtosis(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-kurtosis(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Calculates the centered moving kurtosis of a vector with a given window size and padding.
Arguments
| vector |
vector |
The vector to calculate the centered moving kurtosis of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-kurtosis } = import("Vector");
centered-moving-kurtosis([1, 2, 4, 7, 11, 16], 4)
[
null,
null,
1.761904761904762,
1.6975425330812854,
1.6730681298582533,
null
]
>
let { centered-moving-kurtosis } = import("Vector");
centered-moving-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 0)
[1.628099173553719, 1.8457142857142856, 1.761904761904762, 1.6975425330812854, 1.6730681298582533, 1.7962065107357874]
let { running-kurtosis } = import("Vector")
| Vector.running-kurtosis(vector) |
→ |
array |
Description
Calculates the running kurtosis of a vector with a given window size. First two element in result is null since running kurtosis is not defined for less than three elements.
Arguments
| vector |
vector |
The vector to calculate the running kurtosis of.
|
Examples
>
let { running-kurtosis } = import("Vector");
running-kurtosis([1, 2, 4, 7, 11])
[
null,
null,
null,
1.761904761904762,
1.893939393939394
]
let { sample-excess-kurtosis } = import("Vector")
| Vector.sample-excess-kurtosis(vector) |
→ |
number |
Description
Calculates the sample excess kurtosis of a vector. Returns the third standardized moment.
Arguments
| vector |
vector |
The vector to calculate the sample excess kurtosis of. Minimum length is 3.
|
Examples
>
let { sample-excess-kurtosis } = import("Vector");
sample-excess-kurtosis([1, 2, 3, 6, 20])
3.83206171876871
>
let { sample-excess-kurtosis } = import("Vector");
sample-excess-kurtosis([1, 2, 2, 3])
1.5
let { moving-sample-excess-kurtosis } = import("Vector")
| Vector.moving-sample-excess-kurtosis(vector, windowSize) |
→ |
vector |
Description
Calculates the moving sample excess kurtosis of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving sample excess kurtosis of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-sample-excess-kurtosis } = import("Vector");
moving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)
[-0.2857142857142865, -0.7684310018903613, -0.9519890260630994]
>
let { moving-sample-excess-kurtosis } = import("Vector");
moving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 5)
[-0.42424242424242387, -0.7815570672713532]
let { centered-moving-sample-excess-kurtosis } = import("Vector")
| Vector.centered-moving-sample-excess-kurtosis(vector, windowSize) |
→ |
array |
| Vector.centered-moving-sample-excess-kurtosis(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-sample-excess-kurtosis(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Calculates the centered moving sample excess kurtosis of a vector with a given window size and padding.
Arguments
| vector |
vector |
The vector to calculate the centered moving sample excess kurtosis of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-sample-excess-kurtosis } = import("Vector");
centered-moving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)
[
null,
null,
-0.2857142857142865,
-0.7684310018903613,
-0.9519890260630994,
null
]
>
let { centered-moving-sample-excess-kurtosis } = import("Vector");
centered-moving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 100)
[-1.2892561983471058, 0.3428571428571452, -0.2857142857142865, -0.7684310018903613, -0.9519890260630994, 3.8623010023641378]
let { running-sample-excess-kurtosis } = import("Vector")
| Vector.running-sample-excess-kurtosis(vector) |
→ |
array |
Description
Calculates the running sample excess kurtosis of a vector with a given window size. First two element in result is null since running sample excess kurtosis is not defined for less than three elements.
Arguments
| vector |
vector |
The vector to calculate the running sample excess kurtosis of.
|
Examples
>
let { running-sample-excess-kurtosis } = import("Vector");
running-sample-excess-kurtosis([1, 2, 4, 7, 11])
[
null,
null,
null,
-0.2857142857142865,
-0.42424242424242387
]
let { sample-kurtosis } = import("Vector")
| Vector.sample-kurtosis(vector) |
→ |
number |
Description
Calculates the sample kurtosis of a vector. Returns the third standardized moment.
Arguments
| vector |
vector |
The vector to calculate the sample kurtosis of. Minimum length is 3.
|
Examples
>
let { sample-kurtosis } = import("Vector");
sample-kurtosis([1, 2, 3, 6, 20])
11.83206171876871
>
let { sample-kurtosis } = import("Vector");
sample-kurtosis([1, 2, 2, 3])
15
let { moving-sample-kurtosis } = import("Vector")
| Vector.moving-sample-kurtosis(vector, windowSize) |
→ |
vector |
Description
Calculates the moving sample kurtosis of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving sample kurtosis of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-sample-kurtosis } = import("Vector");
moving-sample-kurtosis([1, 2, 4, 7, 11, 16], 4)
[13.214285714285714, 12.731568998109639, 12.5480109739369]
>
let { moving-sample-kurtosis } = import("Vector");
moving-sample-kurtosis([1, 2, 4, 7, 11, 16], 5)
[7.575757575757576, 7.218442932728647]
let { centered-moving-sample-kurtosis } = import("Vector")
| Vector.centered-moving-sample-kurtosis(vector, windowSize) |
→ |
array |
| Vector.centered-moving-sample-kurtosis(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-sample-kurtosis(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Calculates the centered moving sample kurtosis of a vector with a given window size and padding.
Arguments
| vector |
vector |
The vector to calculate the centered moving sample kurtosis of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-sample-kurtosis } = import("Vector");
centered-moving-sample-kurtosis([1, 2, 4, 7, 11, 16], 4)
[
null,
null,
13.214285714285714,
12.731568998109639,
12.5480109739369,
null
]
>
let { centered-moving-sample-kurtosis } = import("Vector");
centered-moving-sample-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 100)
[12.210743801652894, 13.842857142857145, 13.214285714285714, 12.731568998109639, 12.5480109739369, 17.362301002364138]
let { running-sample-kurtosis } = import("Vector")
| Vector.running-sample-kurtosis(vector) |
→ |
array |
Description
Calculates the running sample kurtosis of a vector with a given window size. First two element in result is null since running sample kurtosis is not defined for less than three elements.
Arguments
| vector |
vector |
The vector to calculate the running sample kurtosis of.
|
Examples
>
let { running-sample-kurtosis } = import("Vector");
running-sample-kurtosis([1, 2, 4, 7, 11])
[
null,
null,
null,
13.214285714285714,
7.575757575757576
]
let { rms } = import("Vector")
Description
Calculates the root mean square of a vector. Returns the square root of the average of the squares of the elements.
Arguments
| vector |
vector |
The vector to calculate the root mean square of. Minimum length is 1.
|
Examples
>
let { rms } = import("Vector");
rms([1, 2, 3, 4])
2.7386127875258306
>
let { rms } = import("Vector");
rms([5, 4, 3, 2, 1])
3.3166247903554
>
let { rms } = import("Vector");
rms(range(1, 1000))
577.2059135756205
>
let { rms, generate } = import("Vector");
rms(generate(1000, -> 1e6 / ($ + 1) ^ 2))
32898.681331906046
>
let { rms, generate } = import("Vector");
rms(generate(1000, -> ln($ + 1)))
5.993615417481764
let { moving-rms } = import("Vector")
| Vector.moving-rms(vector, windowSize) |
→ |
vector |
Description
Calculates the moving root mean square of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving root mean square of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-rms } = import("Vector");
moving-rms([1, 2, 4, 7, 11, 16], 4)
[4.183300132670378, 6.892024376045111, 10.51189802081432]
>
let { moving-rms } = import("Vector");
moving-rms([1, 2, 4, 7, 11, 16], 5)
[6.180614856144977, 9.444575162494075]
>
let { moving-rms } = import("Vector");
moving-rms([1, 2, 4, 7, 11, 16], 6)
[8.631338250816034]
let { centered-moving-rms } = import("Vector")
| Vector.centered-moving-rms(vector, windowSize) |
→ |
vector |
| Vector.centered-moving-rms(vector, windowSize, leftPadding) |
→ |
vector |
| Vector.centered-moving-rms(vector, windowSize, leftPadding, rightPadding) |
→ |
vector |
Description
Calculates the centered moving root mean square of a vector with a given window size and padding value.
Arguments
| vector |
vector |
The vector to calculate the centered moving root mean square of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-rms } = import("Vector");
centered-moving-rms([1, 2, 4, 7, 11, 16], 4)
[
null,
null,
4.183300132670378,
6.892024376045111,
10.51189802081432,
null
]
>
let { centered-moving-rms } = import("Vector");
centered-moving-rms([1, 2, 4, 7, 11, 16], 5, 0)
[
2.04939015319192,
3.7416573867739413,
6.180614856144977,
9.444575162494075,
null,
null
]
>
let { centered-moving-rms } = import("Vector");
centered-moving-rms([1, 2, 4, 7, 11, 16], 6, 0, 0)
[1.8708286933869707, 3.415650255319866, 5.6421036266035856, 8.631338250816034, 8.621678104251709, 8.582928793055823]
let { running-rms } = import("Vector")
| Vector.running-rms(vector) |
→ |
vector |
Description
Calculates the running root mean square of a vector.
Arguments
| vector |
vector |
The vector to calculate the running root mean square of.
|
Examples
>
let { running-rms } = import("Vector");
running-rms([1, 2, 3, 4, 5, 6])
[1, 1.5811388300841898, 2.160246899469287, 2.7386127875258306, 3.3166247903554, 3.8944404818493075]
>
let { running-rms } = import("Vector");
running-rms([1, -3, 2])
[1, 2.23606797749979, 2.160246899469287]
>
let { running-rms } = import("Vector");
running-rms([-1, -2, -3])
[1, 1.5811388300841898, 2.160246899469287]
>
let { running-rms } = import("Vector");
running-rms([0])
[0]
let { mad } = import("Vector")
Description
Returns the mean absolute deviation of all elements in the vector.
Arguments
| vector |
vector |
The vector to calculate the mean absolute deviation of.
|
Examples
>
let { mad } = import("Vector");
mad([1, 2, 3])
0.6666666666666666
>
let { mad } = import("Vector");
mad([1, 2, -3])
1.6666666666666667
let { moving-mad } = import("Vector")
| Vector.moving-mad(vector, windowSize) |
→ |
vector |
Description
Returns the moving mean absolute deviation of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving mean absolute deviation of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-mad } = import("Vector");
moving-mad([1, 2, 3, 4, 5], 3)
[0.6666666666666666, 0.6666666666666666, 0.6666666666666666]
>
let { moving-mad } = import("Vector");
moving-mad([1, 2, 3, 4, 5], 5)
[1.2]
let { centered-moving-mad } = import("Vector")
| Vector.centered-moving-mad(vector, windowSize) |
→ |
array |
| Vector.centered-moving-mad(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-mad(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving mean absolute deviation of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving mean absolute deviation of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-mad } = import("Vector");
centered-moving-mad([1, 2, 3, 4, 5], 3)
[
null,
0.6666666666666666,
0.6666666666666666,
0.6666666666666666,
null
]
>
let { centered-moving-mad } = import("Vector");
centered-moving-mad([1, 2, 3, 4, 5], 5)
[
null,
null,
1.2,
null,
null
]
let { running-mad } = import("Vector")
| Vector.running-mad(vector) |
→ |
vector |
Description
Returns the running mean absolute deviation of the vector.
Arguments
| vector |
vector |
The vector to calculate the running mean absolute deviation of.
|
Examples
>
let { running-mad } = import("Vector");
running-mad([1, 2, 3])
[0, 0.5, 0.6666666666666666]
>
let { running-mad } = import("Vector");
running-mad([1, 2, -3])
[0, 0.5, 1.6666666666666667]
let { medad } = import("Vector")
Description
Returns the median absolute deviation of all elements in the vector.
Arguments
| vector |
vector |
The vector to calculate the median absolute deviation of.
|
Examples
>
let { medad } = import("Vector");
medad([1, 2, 3])
1.4826
>
let { medad } = import("Vector");
medad([1, 2, -3])
1.4826
let { moving-medad } = import("Vector")
| Vector.moving-medad(vector, windowSize) |
→ |
vector |
Description
Returns the moving median absolute deviation of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving median absolute deviation of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-medad } = import("Vector");
moving-medad([1, 2, 3, 4, 5], 3)
[1.4826, 1.4826, 1.4826]
>
let { moving-medad } = import("Vector");
moving-medad([1, 2, 3, 4, 5], 5)
[1.4826]
let { centered-moving-medad } = import("Vector")
| Vector.centered-moving-medad(vector, windowSize) |
→ |
array |
| Vector.centered-moving-medad(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-medad(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving median absolute deviation of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving median absolute deviation of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-medad } = import("Vector");
centered-moving-medad([1, 2, 3, 4, 5], 3)
[
null,
1.4826,
1.4826,
1.4826,
null
]
>
let { centered-moving-medad } = import("Vector");
centered-moving-medad([1, 2, 3, 4, 5], 5)
[
null,
null,
1.4826,
null,
null
]
let { running-medad } = import("Vector")
| Vector.running-medad(vector) |
→ |
vector |
Description
Returns the running median absolute deviation of the vector.
Arguments
| vector |
vector |
The vector to calculate the running median absolute deviation of.
|
Examples
>
let { running-medad } = import("Vector");
running-medad([1, 2, 3])
[0, 0.7413, 1.4826]
>
let { running-medad } = import("Vector");
running-medad([1, 2, -3])
[0, 0.7413, 1.4826]
let { gini-coefficient } = import("Vector")
| Vector.gini-coefficient(vector) |
→ |
number |
Description
Returns the gini coefficient of all elements in the vector.
Arguments
| vector |
vector |
The vector to calculate the gini coefficient of.
|
Examples
>
let { gini-coefficient } = import("Vector");
gini-coefficient([1, 2, 3])
0.22222222222222232
>
let { gini-coefficient } = import("Vector");
gini-coefficient([1, 1, 3])
0.26666666666666683
let { moving-gini-coefficient } = import("Vector")
| Vector.moving-gini-coefficient(vector, windowSize) |
→ |
vector |
Description
Returns the moving gini coefficient of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the moving gini coefficient of.
|
| windowSize |
integer |
The size of the moving window.
|
| a |
vector |
| b |
integer |
Examples
>
let { moving-gini-coefficient } = import("Vector");
moving-gini-coefficient([1, 2, 3], 2)
[0.16666666666666674, 0.10000000000000009]
>
let { moving-gini-coefficient } = import("Vector");
moving-gini-coefficient([1, 1, 3], 2)
[0, 0.25]
let { centered-moving-gini-coefficient } = import("Vector")
| Vector.centered-moving-gini-coefficient(vector, windowSize) |
→ |
array |
| Vector.centered-moving-gini-coefficient(vector, windowSize, leftPadding) |
→ |
array |
| Vector.centered-moving-gini-coefficient(vector, windowSize, leftPadding, rightPadding) |
→ |
array |
Description
Returns the centered moving gini coefficient of the vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving gini coefficient of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-gini-coefficient } = import("Vector");
centered-moving-gini-coefficient([1, 2, 3], 2)
[
null,
0.16666666666666674,
0.10000000000000009
]
>
let { centered-moving-gini-coefficient } = import("Vector");
centered-moving-gini-coefficient([1, 1, 3], 2)
[
null,
0,
0.25
]
let { running-gini-coefficient } = import("Vector")
| Vector.running-gini-coefficient(vector) |
→ |
array |
Description
Returns the running gini coefficient of the vector.
Arguments
| vector |
vector |
The vector to calculate the running gini coefficient of.
|
Examples
>
let { running-gini-coefficient } = import("Vector");
running-gini-coefficient([1, 2, 3])
[0, 0.16666666666666674, 0.22222222222222232]
>
let { running-gini-coefficient } = import("Vector");
running-gini-coefficient([1, 1, 3])
[0, 0, 0.26666666666666683]
let { entropy } = import("Vector")
| Vector.entropy(vector) |
→ |
number |
Description
Calculates the entropy of a vector. The entropy is a measure of the uncertainty associated with a random variable.
Arguments
| vector |
vector |
The vector to calculate the entropy of. Minimum length is 1.
|
Examples
>
let { entropy } = import("Vector");
entropy([1, 1, 2, 3, 3, 3])
1.4591479170272448
>
let { entropy } = import("Vector");
entropy([1, 2, 3])
1.584962500721156
>
let { entropy } = import("Vector");
entropy([1, 2, 2, 3])
1.5
>
let { entropy } = import("Vector");
entropy([0])
0
>
let { entropy } = import("Vector");
entropy([1])
0
>
let { entropy } = import("Vector");
entropy([1, 2])
1
let { moving-entropy } = import("Vector")
| Vector.moving-entropy(vector, windowSize) |
→ |
vector |
Description
Calculates the moving entropy of a vector with a given window size.
Examples
>
let { moving-entropy } = import("Vector");
moving-entropy([1, 1, 2, 3, 3, 3], 4)
[1.5, 1.5, 0.8112781244591328]
>
let { moving-entropy } = import("Vector");
moving-entropy([1, 1, 2, 3, 3, 3], 3)
[0.9182958340544896, 1.584962500721156, 0.9182958340544896, 0]
>
let { moving-entropy } = import("Vector");
moving-entropy([1, 2], 2)
[1]
let { centered-moving-entropy } = import("Vector")
| Vector.centered-moving-entropy(vector, windowSize) |
→ |
vector |
| Vector.centered-moving-entropy(vector, windowSize, leftPadding) |
→ |
vector |
| Vector.centered-moving-entropy(vector, windowSize, leftPadding, rightPadding) |
→ |
vector |
Description
Calculates the centered moving entropy of a vector with a given window size.
Arguments
| vector |
vector |
The vector to calculate the centered moving entropy of.
|
| windowSize |
integer |
The size of the moving window.
|
| leftPadding |
number |
Optional value to use for padding. Default is null.
|
| rightPadding |
number |
Optional value to use for right padding. Default is null.
|
| a |
vector |
| b |
integer |
Examples
>
let { centered-moving-entropy } = import("Vector");
centered-moving-entropy([1, 1, 2, 3, 3, 3], 4)
[
null,
null,
1.5,
1.5,
0.8112781244591328,
null
]
>
let { centered-moving-entropy } = import("Vector");
centered-moving-entropy([1, 1, 2, 3, 3, 3], 3)
[
null,
0.9182958340544896,
1.584962500721156,
0.9182958340544896,
0,
null
]
>
let { centered-moving-entropy } = import("Vector");
centered-moving-entropy([1, 2], 2)
[
null,
1
]
let { running-entropy } = import("Vector")
| Vector.running-entropy(vector) |
→ |
vector |
Description
Calculates the running entropy of a vector.
Arguments
| vector |
vector |
The vector to calculate the running entropy of.
|
Examples
>
let { running-entropy } = import("Vector");
running-entropy([1, 1, 2, 3, 3, 3])
[0, 0, 0.9182958340544896, 1.5, 1.5219280948873621, 1.4591479170272448]
>
let { running-entropy } = import("Vector");
running-entropy([1, 2])
[0, 1]
let { monotonic? } = import("Vector")
| Vector.monotonic?(vector) |
→ |
boolean |
Description
Checks if a vector is monotonic.
Arguments
| vector |
vector |
The vector to check.
|
Examples
>
let { monotonic? } = import("Vector");
monotonic?([1, 2, 3])
true
>
let { monotonic? } = import("Vector");
monotonic?([1, 2, 2, 3])
true
>
let { monotonic? } = import("Vector");
monotonic?([3, 2, 1])
true
>
let { monotonic? } = import("Vector");
monotonic?([3, 2, 1, 1])
true
>
let { monotonic? } = import("Vector");
monotonic?([3, 2, 1, 2])
false
>
let { monotonic? } = import("Vector");
monotonic?([1])
true
>
let { monotonic? } = import("Vector");
monotonic?([])
true
let { strictly-monotonic? } = import("Vector")
| Vector.strictly-monotonic?(vector) |
→ |
boolean |
Description
Checks if a vector is strictly monotonic.
Arguments
| vector |
vector |
The vector to check.
|
Examples
>
let { strictly-monotonic? } = import("Vector");
strictly-monotonic?([1, 2, 3])
true
>
let { strictly-monotonic? } = import("Vector");
strictly-monotonic?([1, 2, 2, 3])
false
>
let { strictly-monotonic? } = import("Vector");
strictly-monotonic?([3, 2, 1])
true
>
let { strictly-monotonic? } = import("Vector");
strictly-monotonic?([3, 2, 1, 1])
false
>
let { strictly-monotonic? } = import("Vector");
strictly-monotonic?([3, 2, 1, 2])
false
>
let { strictly-monotonic? } = import("Vector");
strictly-monotonic?([1])
true
>
let { strictly-monotonic? } = import("Vector");
strictly-monotonic?([])
true
let { increasing? } = import("Vector")
| Vector.increasing?(vector) |
→ |
boolean |
Description
Checks if a vector is increasing.
Arguments
| vector |
vector |
The vector to check.
|
Examples
>
let { increasing? } = import("Vector");
increasing?([1, 2, 3])
true
>
let { increasing? } = import("Vector");
increasing?([1, 2, 2, 3])
true
>
let { increasing? } = import("Vector");
increasing?([3, 2, 1])
false
>
let { increasing? } = import("Vector");
increasing?([3, 2, 1, 1])
false
>
let { increasing? } = import("Vector");
increasing?([3, 2, 1, 2])
false
>
let { increasing? } = import("Vector");
increasing?([1])
true
>
let { increasing? } = import("Vector");
increasing?([])
true
let { decreasing? } = import("Vector")
| Vector.decreasing?(vector) |
→ |
boolean |
Description
Checks if a vector is decreasing.
Arguments
| vector |
vector |
The vector to check.
|
Examples
>
let { decreasing? } = import("Vector");
decreasing?([1, 2, 3])
false
>
let { decreasing? } = import("Vector");
decreasing?([1, 2, 2, 3])
false
>
let { decreasing? } = import("Vector");
decreasing?([3, 2, 1])
true
>
let { decreasing? } = import("Vector");
decreasing?([3, 2, 1, 1])
true
>
let { decreasing? } = import("Vector");
decreasing?([3, 2, 1, 2])
false
>
let { decreasing? } = import("Vector");
decreasing?([1])
true
>
let { decreasing? } = import("Vector");
decreasing?([])
true
let { strictly-increasing? } = import("Vector")
| Vector.strictly-increasing?(vector) |
→ |
boolean |
Description
Checks if a vector is strictly increasing.
Arguments
| vector |
vector |
The vector to check.
|
Examples
>
let { strictly-increasing? } = import("Vector");
strictly-increasing?([1, 2, 3])
true
>
let { strictly-increasing? } = import("Vector");
strictly-increasing?([1, 2, 2, 3])
false
>
let { strictly-increasing? } = import("Vector");
strictly-increasing?([3, 2, 1])
false
>
let { strictly-increasing? } = import("Vector");
strictly-increasing?([3, 2, 1, 1])
false
>
let { strictly-increasing? } = import("Vector");
strictly-increasing?([3, 2, 1, 2])
false
>
let { strictly-increasing? } = import("Vector");
strictly-increasing?([1])
true
>
let { strictly-increasing? } = import("Vector");
strictly-increasing?([])
true
let { strictly-decreasing? } = import("Vector")
| Vector.strictly-decreasing?(vector) |
→ |
boolean |
Description
Checks if a vector is strictly decreasing.
Arguments
| vector |
vector |
The vector to check.
|
Examples
>
let { strictly-decreasing? } = import("Vector");
strictly-decreasing?([1, 2, 3])
false
>
let { strictly-decreasing? } = import("Vector");
strictly-decreasing?([1, 2, 2, 3])
false
>
let { strictly-decreasing? } = import("Vector");
strictly-decreasing?([3, 2, 1])
true
>
let { strictly-decreasing? } = import("Vector");
strictly-decreasing?([3, 2, 1, 1])
false
>
let { strictly-decreasing? } = import("Vector");
strictly-decreasing?([3, 2, 1, 2])
false
>
let { strictly-decreasing? } = import("Vector");
strictly-decreasing?([1])
true
>
let { strictly-decreasing? } = import("Vector");
strictly-decreasing?([])
true
let { mode } = import("Vector")
Description
Returns the mode of all elements in the vector.
Arguments
| vector |
vector |
The vector to calculate the mode of.
|
Examples
>
let { mode } = import("Vector");
mode([1, 2, 3])
[1, 2, 3]
>
let { mode } = import("Vector");
mode([1, 2, -3, 1])
[1]
>
let { mode } = import("Vector");
mode([2, 2, 3, 3, 4])
[2, 3]
>
let { mode } = import("Vector");
mode([2, 2, 3, 3])
[2, 3]
>
let { mode } = import("Vector");
mode([1, 2, 3, 2, 1, 2])
[2]
let { min-index } = import("Vector")
Description
Returns the index of the minimum value of all elements in the vector.
Arguments
| vector |
vector |
Non emtpy vector to calculate the minimum index of.
|
Examples
>
let { min-index } = import("Vector");
min-index([1, 2, 3])
0
>
let { min-index } = import("Vector");
min-index([1, 1, 2, 3, 3])
0
>
let { min-index } = import("Vector");
min-index([1, 2, -3])
2
>
let { min-index } = import("Vector");
min-index([1, 2, 3, 4])
0
>
let { min-index } = import("Vector");
min-index([1, 2, -3, 4])
2
let { max-index } = import("Vector")
Description
Returns the index of the maximum value of all elements in the vector.
Arguments
| vector |
vector |
Non emtpy vector to calculate the maximum index of.
|
Examples
>
let { max-index } = import("Vector");
max-index([1, 2, 3])
2
>
let { max-index } = import("Vector");
max-index([1, 1, 2, 3, 3])
3
>
let { max-index } = import("Vector");
max-index([1, 2, -3])
1
>
let { max-index } = import("Vector");
max-index([1, 2, 3, 4])
3
>
let { max-index } = import("Vector");
max-index([1, 2, -3, 4])
3
let { sort-indices } = import("Vector")
| Vector.sort-indices(vector) |
→ |
vector |
Description
Returns the indices of the elements in the vector sorted in ascending order.
Arguments
| vector |
vector |
Non emtpy vector to calculate the sorted indices of.
|
Examples
>
let { sort-indices } = import("Vector");
sort-indices([1, 2, 3])
[0, 1, 2]
>
let { sort-indices } = import("Vector");
sort-indices([1, 1, 2, 3, 3])
[0, 1, 2, 3, 4]
>
let { sort-indices } = import("Vector");
sort-indices([1, 2, -3])
[2, 0, 1]
>
let { sort-indices } = import("Vector");
sort-indices([1, 2, 3, 4])
[0, 1, 2, 3]
>
let { sort-indices } = import("Vector");
sort-indices([1, 2, -3, 4])
[2, 0, 1, 3]
let { count-values } = import("Vector")
| Vector.count-values(vector) |
→ |
Array<number> |
Description
Counts the number of occurrences of each value in the vector.
Arguments
| vector |
vector |
Vector to count the values of.
|
Examples
>
let { count-values } = import("Vector");
count-values([1, 2, 3])
[ 1 1 ]
[ 2 1 ]
[ 3 1 ]
>
let { count-values } = import("Vector");
count-values([1, 1, 2, 3, 3])
[ 1 2 ]
[ 3 2 ]
[ 2 1 ]
>
let { count-values } = import("Vector");
count-values([1, 2, -3])
[ -3 1 ]
[ 1 1 ]
[ 2 1 ]
>
let { count-values } = import("Vector");
count-values([1, 2, 2, 1, 3, 2, 4, 2, 1, 2, 2, 1, 3, 2, 4])
[ 2 7 ]
[ 1 4 ]
[ 3 2 ]
[ 4 2 ]
let { linspace } = import("Vector")
| Vector.linspace(start, stop, n) |
→ |
Array<number> |
Description
Generates a vector of evenly spaced numbers between two values.
Arguments
| start |
number |
The starting value.
|
| stop |
number |
The ending value.
|
| n |
integer |
The number of values to generate.
|
Examples
>
let { linspace } = import("Vector");
linspace(0, 10, 6)
[0, 2, 4, 6, 8, 10]
>
let { linspace } = import("Vector");
linspace(10, 20, 25)
[
10,
10.416666666666666,
10.833333333333334,
11.25,
11.666666666666666,
12.083333333333334,
12.5,
12.916666666666668,
13.333333333333334,
13.75,
14.166666666666668,
14.583333333333334,
15,
15.416666666666668,
15.833333333333334,
16.25,
16.666666666666668,
17.083333333333336,
17.5,
17.916666666666668,
18.333333333333336,
18.75,
19.166666666666668,
19.583333333333336,
20
]
let { ones } = import("Vector")
| Vector.ones(length) |
→ |
Array<number> |
Description
Generates a vector of ones.
Arguments
| length |
integer |
The length of the vector.
|
Examples
>
let { ones } = import("Vector");
ones(5)
[1, 1, 1, 1, 1]
>
let { ones } = import("Vector");
ones(10)
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
]
>
let { ones } = import("Vector");
ones(0)
[]
let { zeros } = import("Vector")
| Vector.zeros(length) |
→ |
Array<number> |
Description
Generates a vector of zeros.
Arguments
| length |
integer |
The length of the vector.
|
Examples
>
let { zeros } = import("Vector");
zeros(5)
[0, 0, 0, 0, 0]
>
let { zeros } = import("Vector");
zeros(10)
[
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
]
>
let { zeros } = import("Vector");
zeros(0)
[]
let { fill } = import("Vector")
| Vector.fill(length, value) |
→ |
Array<number> |
Description
Generates a vector filled with a number.
Examples
>
let { fill } = import("Vector");
fill(5, PI)
[3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793, 3.141592653589793]
>
let { fill } = import("Vector");
fill(10, -1)
[
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
]
let { generate } = import("Vector")
| Vector.generate(length, func) |
→ |
Array<number> |
Description
Generates a vector of numbers based on a function.
Examples
>
let { generate } = import("Vector");
generate(5, -> $ * 2)
[0, 2, 4, 6, 8]
>
let { generate } = import("Vector");
generate(10, -> $ + 1)
[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
]
>
let { generate } = import("Vector");
generate(0, -> $ + 1)
[]
let { cumsum } = import("Vector")
| Vector.cumsum(vector) |
→ |
Array<number> |
Description
Calculates the cumulative sum of a vector.
Arguments
| vector |
vector |
The vector to calculate the cumulative sum of.
|
Examples
>
let { cumsum } = import("Vector");
cumsum([1, 2, 3])
[1, 3, 6]
>
let { cumsum } = import("Vector");
cumsum([1, 2, -3])
[1, 3, 0]
>
let { cumsum } = import("Vector");
cumsum([])
[]
let { cumprod } = import("Vector")
| Vector.cumprod(vector) |
→ |
Array<number> |
Description
Calculates the cumulative product of a vector.
Arguments
| vector |
vector |
The vector to calculate the cumulative product of.
|
Examples
>
let { cumprod } = import("Vector");
cumprod([1, 2, 3])
[1, 2, 6]
>
let { cumprod } = import("Vector");
cumprod([1, 2, -3, 0, 10])
[1, 2, -6, 0, 0]
>
let { cumprod } = import("Vector");
cumprod([])
[]
let { quartiles } = import("Vector")
| Vector.quartiles(vector) |
→ |
Array<number> |
Description
Calculates the quartiles of a vector. Returns an array containing the first, second (median), and third quartiles.
Arguments
| vector |
vector |
The vector to calculate the quartiles of. Minimum length is 4.
|
Examples
>
let { quartiles } = import("Vector");
quartiles([1, 2, 3, 4])
[1.5, 2.5, 3.5]
>
let { quartiles } = import("Vector");
quartiles([5, 4, 3, 2, 1, 2, 3, 4, 5])
[2, 3, 4.5]
>
let { quartiles } = import("Vector");
quartiles(range(1, 1000))
[250, 500, 750]
>
let { quartiles, generate } = import("Vector");
quartiles(generate(1000, -> 1e6 / ($ + 1) ^ 2))
[1.7754121397341889, 3.992023936159617, 15.936381962191076]
>
let { quartiles, generate } = import("Vector");
quartiles(generate(1000, -> ln($ + 1)))
[5.523456928497015, 6.215607099753528, 6.620739429147245]
let { percentile } = import("Vector")
| Vector.percentile(vector, percentile) |
→ |
number |
Description
Calculates the percentile of a vector. Returns the value at the specified percentile.
Arguments
| vector |
vector |
The non empty vector to calculate the percentile of.
|
| percentile |
number |
The percentile to calculate. Must be between 0 and 1.
|
| a |
number |
| b |
integer |
Examples
>
let { percentile } = import("Vector");
percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 35)
4.15
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 0)
0
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 10)
3.146049894151542
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 20)
4.449488552707798
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 30)
5.449607344676513
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 40)
6.292732391561415
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 50)
7.035533905932738
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 60)
7.7070741256870985
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 70)
8.324616783644878
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 80)
8.899409915852303
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 90)
9.439266316901458
>
let { percentile } = import("Vector");
percentile(range(100) ^ 0.5, 100)
9.9498743710662
let { quantile } = import("Vector")
| Vector.quantile(vector, quantile) |
→ |
number |
Description
Calculates the quantile of a vector. Returns the value at the specified quantile.
Arguments
| vector |
vector |
The non empty vector to calculate the quantile of.
|
| quantile |
number |
The quantile to calculate. Must be between 0 and 1.
|
| a |
number |
| b |
integer |
Examples
>
let { quantile } = import("Vector");
quantile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0.35)
4.15
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 0)
0
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 0.1)
3.146049894151542
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 0.2)
4.449488552707798
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 0.3)
5.449607344676513
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 0.4)
6.292732391561415
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 0.5)
7.035533905932738
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 0.6)
7.7070741256870985
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 0.7)
8.324616783644878
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 0.8)
8.899409915852303
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 0.9)
9.439266316901458
>
let { quantile } = import("Vector");
quantile(range(100) ^ 0.5, 1)
9.9498743710662
let { histogram } = import("Vector")
| Vector.histogram(vector, bins) |
→ |
Array<array> |
Description
Creates a histogram from a numeric array by dividing the data range into the specified number of bins. Returns an array of [binStart, binEnd, count] tuples representing each bin's range and the number of values within it. Handles empty arrays, identical values, and properly places maximum values in the last bin.
Arguments
| vector |
vector |
The numeric array to create a histogram from.
|
| bins |
integer |
The number of bins to divide the data range into.
|
| a |
number |
| b |
integer |
Examples
>
let { histogram } = import("Vector");
histogram([1, 2, 2, 3, 2, 6, 4, 3, 2, 4, 1, 3, 2, 9], 3)
[ 1 3.6666666666666665 10 ]
[ 3.6666666666666665 6.333333333333333 3 ]
[ 6.333333333333333 9 1 ]
>
let { histogram } = import("Vector");
histogram([1, 2, 3, 4, 5], 5)
[ 1 1.8 1 ]
[ 1.8 2.6 1 ]
[ 2.6 3.4000000000000004 1 ]
[ 3.4000000000000004 4.2 1 ]
[ 4.2 5 1 ]
>
let { histogram } = import("Vector");
histogram([1, 2, 3, 4, 5], 10)
[ 1 1.4 1 ]
[ 1.4 1.8 0 ]
[ 1.8 2.2 1 ]
[ 2.2 2.6 0 ]
[ 2.6 3 0 ]
[ 3 3.4000000000000004 1 ]
[ 3.4000000000000004 3.8000000000000003 0 ]
[ 3.8000000000000003 4.2 1 ]
[ 4.2 4.6 0 ]
[ 4.6 5 1 ]
>
let { histogram } = import("Vector");
histogram([1, 2, 3, 4, 5], 1)
[ 1 5 5 ]
let { ecdf } = import("Vector")
| Vector.ecdf(vector, threshold) |
→ |
number |
Description
Calculates the empirical cumulative distribution function value for a given threshold in a non empty dataset. Returns the proportion of values in the array that are less than or equal to the specified threshold.
Arguments
| vector |
vector |
The numeric array to calculate the ECDF from.
|
| threshold |
number |
The threshold value to calculate the ECDF for.
|
| a |
number |
| b |
integer |
Examples
>
let { ecdf } = import("Vector");
ecdf([1, 2, 2, 3, 2, 6, 4, 3, 2, 4, 1, 3, 2, 9, 10, 12], 5)
0.75
>
let { ecdf } = import("Vector");
ecdf([1, 2, 3, 4, 5], 3)
0.6
>
let { ecdf } = import("Vector");
ecdf([1, 2, 3, 4, 5], 0)
0
>
let { ecdf } = import("Vector");
ecdf([1, 2, 3, 4, 5], 10)
1
>
let { ecdf } = import("Vector");
ecdf([1, 2, 3, 4, 5], 2)
0.4
let { outliers? } = import("Vector")
Description
Checks if the vector contains outliers based on the interquartile range (IQR) method. Returns true if outliers are present, false otherwise.
Arguments
| vector |
vector |
The vector to check for outliers.
|
Examples
>
let { outliers? } = import("Vector");
outliers?([1, 2, 3])
false
>
let { outliers? } = import("Vector");
outliers?([1, 2, -3])
false
>
let { outliers? } = import("Vector");
outliers?([1, 2, 3, 2, 4, 120])
true
let { outliers } = import("Vector")
| Vector.outliers(vector) |
→ |
Array<number> |
Description
Identifies outliers in the vector based on the interquartile range (IQR) method. Returns an array of outlier values.
Arguments
| vector |
vector |
The vector to check for outliers.
|
Examples
>
let { outliers } = import("Vector");
outliers([1, 2, 3])
[]
>
let { outliers } = import("Vector");
outliers([1, 2, -3])
[]
>
let { outliers } = import("Vector");
outliers([1, 2, 3, 2, 4, 120])
[120]
let { bincount } = import("Vector")
| Vector.bincount(vector) |
→ |
vector |
| Vector.bincount(vector, minSize) |
→ |
vector |
| Vector.bincount(vector, minSize, weights) |
→ |
vector |
Description
counts occurrences of each integer in a vector, returning an array where index i contains the count of value i, with optional minimum size and weights parameters.
Arguments
| vector |
vector |
The vector to count occurrences in.
|
| minSize |
integer |
Optional minimum size of the output array.
|
| weights |
Array<number> |
Optional weights for each element in the vector.
|
Examples
>
let { bincount } = import("Vector");
bincount([1, 2, 3])
[0, 1, 1, 1]
>
let { bincount } = import("Vector");
bincount([1, 2, 2, 3, 3])
[0, 1, 2, 2]
let { winsorize } = import("Vector")
| Vector.winsorize(vector, lower-quantile) |
→ |
vector |
| Vector.winsorize(vector, lower-quantile, upper-quantile) |
→ |
vector |
Description
Limits extreme values in a vector by replacing values below the lower quantile and above the upper quantile with the values at those quantiles. The function takes a vector of values and quantile thresholds (between 0 and 1), with the upper quantile. Winsorization reduces the influence of outliers while preserving the overall distribution shape, making statistical analyses more robust.
Arguments
| vector |
vector |
The vector to winsorize.
|
| lower-quantile |
number |
The lower quantile threshold (between 0 and 1).
|
| upper-quantile |
number |
Optional Upper quantile threshold (between 0 and 1). Defaults to (1 - lower-quantile) if lower-quantile <= 0.5 otherwise 1.
|
Examples
>
let { winsorize } = import("Vector");
winsorize([2, 5, 8, 10, 15, 18, 20, 35, 60, 100], 0.25)
[
8,
8,
8,
10,
15,
18,
20,
20,
20,
20
]
>
let { winsorize } = import("Vector");
winsorize([2, 5, 8, 10, 15, 18, 20, 35, 60, 100], 0.25, 0.75)
[
8,
8,
8,
10,
15,
18,
20,
20,
20,
20
]
>
let { winsorize } = import("Vector");
winsorize([2, 5, 8, 10, 15, 18, 20, 35, 60, 100], 0.25, 0.5)
[
8,
8,
8,
10,
15,
15,
15,
15,
15,
15
]
let { mse } = import("Vector")
Description
Calculates the Mean Squared Error (MSE) between two vectors. Returns the average of the squared differences between corresponding elements.
Examples
>
let { mse } = import("Vector");
mse([1, 2, 3], [1, 2, 3])
0
>
let { mse } = import("Vector");
mse([1, 2, 3], [4, 5, 6])
9
>
let { mse } = import("Vector");
mse([1, 2, 3], [2, 2, 2])
0.6666666666666666
>
let { mse } = import("Vector");
mse([1, 2], [3, 3])
2.5
>
let { mse } = import("Vector");
mse([1], [3])
4
let { rmse } = import("Vector")
Description
Calculates the Root Mean Squared Error (RMSE) between two vectors. Returns the square root of the average of the squared differences between corresponding elements.
Examples
>
let { rmse } = import("Vector");
rmse([1, 2, 3], [1, 2, 3])
0
>
let { rmse } = import("Vector");
rmse([1, 2, 3], [4, 5, 6])
3
>
let { rmse } = import("Vector");
rmse([1, 2, 3], [2, 2, 2])
0.816496580927726
>
let { rmse } = import("Vector");
rmse([1, 2], [3, 3])
1.5811388300841898
>
let { rmse } = import("Vector");
rmse([1], [3])
2
let { mae } = import("Vector")
Description
Calculates the Mean Absolute Error (MAE) between two vectors. Returns the average of the absolute differences between corresponding elements.
Examples
>
let { mae } = import("Vector");
mae([1, 2, 3], [1, 2, 3])
0
>
let { mae } = import("Vector");
mae([1, 2, 3], [4, 5, 6])
3
>
let { mae } = import("Vector");
mae([1, 2, 3], [2, 2, 2])
0.6666666666666666
>
let { mae } = import("Vector");
mae([1, 2], [3, 3])
1.5
>
let { mae } = import("Vector");
mae([1], [3])
2
let { smape } = import("Vector")
Description
Calculates the Symmetric Mean Absolute Percentage Error (SMAPE) between two vectors. Returns the average of the absolute percentage differences between corresponding elements.
Examples
>
let { smape } = import("Vector");
smape([1, 2, 3], [1, 2, 3])
0
>
let { smape } = import("Vector");
smape([1, 2, 3], [4, 5, 6])
0.9079365079365078
>
let { smape } = import("Vector");
smape([1, 2, 3], [2, 2, 2])
0.35555555555555557
>
let { smape } = import("Vector");
smape([1, 2], [3, 3])
0.7
>
let { smape } = import("Vector");
smape([1], [3])
1
let { reflect } = import("Linear-Algebra")
| Linear-Algebra.reflect(a, b) |
→ |
vector |
Description
Reflects a vector across a given axis.
Examples
>
let { reflect } = import("Linear-Algebra");
reflect([1, 2], [0, 1])
[1, -2]
>
let { reflect } = import("Linear-Algebra");
reflect([1, 2, 3], [0, 0, 1])
[1, 2, -3]
let { refract } = import("Linear-Algebra")
| Linear-Algebra.refract(vector, axis, eta) |
→ |
vector |
Description
Refracts a vector across a given axis.
Arguments
| vector |
vector |
Vector to refract.
|
| axis |
vector |
Axis of refraction.
|
| eta |
number |
Refraction index.
|
Examples
>
let { refract } = import("Linear-Algebra");
refract([1, 2], [0, 1], 1.5)
[0.6708203932499369, -0.741619848709566]
>
let { refract } = import("Linear-Algebra");
refract([1, 2, 3], [0, 0, 1], 1.5)
[0.4008918628686366, 0.8017837257372732, -0.44320263021395934]
let { lerp } = import("Linear-Algebra")
| Linear-Algebra.lerp(a, b, t) |
→ |
vector |
Description
Performs linear interpolation between two vectors.
Examples
>
let { lerp } = import("Linear-Algebra");
lerp([1, 2], [3, 4], 0.5)
[2, 3]
>
let { lerp } = import("Linear-Algebra");
lerp([1, 2], [3, 4], 2)
[5, 6]
>
let { lerp } = import("Linear-Algebra");
lerp([1, 2], [3, 4], -1)
[-1, 0]
>
let { lerp } = import("Linear-Algebra");
lerp([1, 2, 3], [4, 5, 6], 0.25)
[1.75, 2.75, 3.75]
let { rotate2d } = import("Linear-Algebra")
| Linear-Algebra.rotate2d(a, b) |
→ |
vector |
Description
Rotates a 2D vector by a given angle in radians.
Examples
>
let { rotate2d } = import("Linear-Algebra");
rotate2d([1, 0], PI / 2)
[6.123233995736766e-17, 1]
>
let { rotate2d } = import("Linear-Algebra");
rotate2d([0, 1], PI)
[-1.2246467991473532e-16, -1]
let { rotate3d } = import("Linear-Algebra")
| Linear-Algebra.rotate3d(v, axis, radians) |
→ |
vector |
Description
Rotates a 3D vector around a given axis by a given angle in radians.
Examples
>
let { rotate3d } = import("Linear-Algebra");
rotate3d([1, 0, 0], [0, 1, 0], PI / 2)
[6.123233995736766e-17, 0, -1]
>
let { rotate3d } = import("Linear-Algebra");
rotate3d([0, 1, 0], [1, 0, 0], PI)
[0, -1, 1.2246467991473532e-16]
let { dot } = import("Linear-Algebra")
| Linear-Algebra.dot(a, b) |
→ |
number |
Description
Calculates the dot product of two vectors. The result is a scalar.
Examples
>
let { dot } = import("Linear-Algebra");
dot([1, 2], [3, 4])
11
>
let { dot } = import("Linear-Algebra");
dot([1, 2, 3], [4, 5, 6])
32
let { cross } = import("Linear-Algebra")
| Linear-Algebra.cross(a, b) |
→ |
vector |
Description
Calculates the cross product of two 3D vectors. The result is a vector perpendicular to both input vectors.
Examples
>
let { cross } = import("Linear-Algebra");
cross([1, 2, 3], [4, 5, 6])
[-3, 6, -3]
>
let { cross } = import("Linear-Algebra");
cross([1, 0, 0], [0, 1, 0])
[0, 0, 1]
>
let { cross } = import("Linear-Algebra");
cross([0, 0, 1], [1, 0, 0])
[0, 1, 0]
>
let { cross } = import("Linear-Algebra");
cross([1, 2, 3], [0, 0, 0])
[0, 0, 0]
>
let { cross } = import("Linear-Algebra");
cross([0, 0, 0], [1, 2, 3])
[0, 0, 0]
let { normalize-minmax } = import("Linear-Algebra")
| Linear-Algebra.normalize-minmax(v) |
→ |
number |
Description
Normalizes the vector using min-max normalization. The result is a vector with values between 0 and 1.
Examples
>
let { normalize-minmax } = import("Linear-Algebra");
normalize-minmax([1, 2, 3])
[0, 0.5, 1]
>
let { normalize-minmax } = import("Linear-Algebra");
normalize-minmax([1, 2, -3])
[0.8, 1, 0]
>
let { normalize-minmax } = import("Linear-Algebra");
normalize-minmax([1, 2, 3, 4])
[0, 0.3333333333333333, 0.6666666666666666, 1]
>
let { normalize-minmax } = import("Linear-Algebra");
normalize-minmax([1, 2, -3, 4])
[0.5714285714285714, 0.7142857142857143, 0, 1]
>
let { normalize-minmax } = import("Linear-Algebra");
normalize-minmax([1, 2, 3, 40, 50])
[0, 0.02040816326530612, 0.04081632653061224, 0.7959183673469388, 1]
let { normalize-zscore } = import("Linear-Algebra")
| Linear-Algebra.normalize-zscore(v) |
→ |
number |
Description
Normalizes the vector using z-score normalization. The result is a vector with mean 0 and standard deviation 1.
Examples
>
let { normalize-zscore } = import("Linear-Algebra");
normalize-zscore([1, 2, 3])
[-1.224744871391589, 0, 1.224744871391589]
>
let { normalize-zscore } = import("Linear-Algebra");
normalize-zscore([1, 2, -3])
[0.4629100498862757, 0.9258200997725514, -1.3887301496588271]
>
let { normalize-zscore } = import("Linear-Algebra");
normalize-zscore([1, 2, 3, 4])
[-1.3416407864998738, -0.4472135954999579, 0.4472135954999579, 1.3416407864998738]
>
let { normalize-zscore } = import("Linear-Algebra");
normalize-zscore([1, 2, -3, 4])
[0, 0.3922322702763681, -1.5689290811054724, 1.1766968108291043]
>
let { normalize-zscore } = import("Linear-Algebra");
normalize-zscore([1, 2, 3, 40, 50])
[-0.8540178486542159, -0.8070937910358524, -0.760169733417489, 0.9760203984619611, 1.4452609746455962]
let { normalize-robust } = import("Linear-Algebra")
| Linear-Algebra.normalize-robust(v) |
→ |
number |
Description
Normalizes the vector using robust normalization. The result is a vector with median 0 and median absolute deviation 1.
Examples
>
let { normalize-robust } = import("Linear-Algebra");
normalize-robust([1, 2, 3])
[-0.6744907594765952, 0, 0.6744907594765952]
>
let { normalize-robust } = import("Linear-Algebra");
normalize-robust([1, 2, -3])
[0, 0.6744907594765952, -2.697963037906381]
>
let { normalize-robust } = import("Linear-Algebra");
normalize-robust([1, 2, 3, 4])
[-1.011736139214893, -0.3372453797382976, 0.3372453797382976, 1.011736139214893]
>
let { normalize-robust } = import("Linear-Algebra");
normalize-robust([1, 2, -3, 4])
[-0.22483025315886507, 0.22483025315886507, -2.0234722784297854, 1.1241512657943253]
>
let { normalize-robust } = import("Linear-Algebra");
normalize-robust([1, 2, 3, 40, 50])
[-0.6744907594765952, -0.3372453797382976, 0, 12.478079050317012, 15.850532847699988]
let { normalize-l1 } = import("Linear-Algebra")
| Linear-Algebra.normalize-l1(v) |
→ |
number |
Description
Normalizes the vector using L1 normalization. The result is a vector with L1 norm equal to 1.
Examples
>
let { normalize-l1 } = import("Linear-Algebra");
normalize-l1([1, 2, 3])
[0.16666666666666666, 0.3333333333333333, 0.5]
>
let { normalize-l1 } = import("Linear-Algebra");
normalize-l1([1, 2, -3])
[0.16666666666666666, 0.3333333333333333, -0.5]
>
let { normalize-l1 } = import("Linear-Algebra");
normalize-l1([1, 2, 3, 4])
[0.1, 0.2, 0.3, 0.4]
>
let { normalize-l1 } = import("Linear-Algebra");
normalize-l1([1, 2, -3, 4])
[0.1, 0.2, -0.3, 0.4]
>
let { normalize-l1 } = import("Linear-Algebra");
normalize-l1([1, 2, 3, 40, 50])
[0.010416666666666666, 0.020833333333333332, 0.03125, 0.4166666666666667, 0.5208333333333334]
let { normalize-l2 } = import("Linear-Algebra")
| Linear-Algebra.normalize-l2(v) |
→ |
number |
Description
Normalizes the vector using L2 normalization. The result is a vector with L2 norm equal to 1.
Examples
>
let { normalize-l2 } = import("Linear-Algebra");
normalize-l2([1, 2, 3])
[0.2672612419124244, 0.5345224838248488, 0.8017837257372732]
>
let { normalize-l2 } = import("Linear-Algebra");
normalize-l2([1, 2, 3])
[0.2672612419124244, 0.5345224838248488, 0.8017837257372732]
>
let { normalize-l2 } = import("Linear-Algebra");
normalize-l2([1, 2, -3])
[0.2672612419124244, 0.5345224838248488, -0.8017837257372732]
>
let { normalize-l2 } = import("Linear-Algebra");
normalize-l2([1, 2, 3, 4])
[0.18257418583505536, 0.3651483716701107, 0.5477225575051661, 0.7302967433402214]
>
let { normalize-l2 } = import("Linear-Algebra");
normalize-l2([1, 2, -3, 4])
[0.18257418583505536, 0.3651483716701107, -0.5477225575051661, 0.7302967433402214]
>
let { normalize-l2 } = import("Linear-Algebra");
normalize-l2([1, 2, 3, 40, 50])
[0.015590780467500804, 0.031181560935001608, 0.046772341402502415, 0.6236312187000321, 0.7795390233750402]
let { normalize-log } = import("Linear-Algebra")
| Linear-Algebra.normalize-log(v) |
→ |
number |
Description
Normalizes the vector using natural log normalization. The result is a vector with log-transformed values.
Examples
>
let { normalize-log } = import("Linear-Algebra");
normalize-log([1, 2, 3])
[0, 0.6931471805599453, 1.0986122886681096]
>
let { normalize-log } = import("Linear-Algebra");
normalize-log([1, 2, 3, 4])
[0, 0.6931471805599453, 1.0986122886681096, 1.3862943611198906]
>
let { normalize-log } = import("Linear-Algebra");
normalize-log([1, 2, 3, 40, 50])
[0, 0.6931471805599453, 1.0986122886681096, 3.6888794541139363, 3.912023005428146]
let { angle } = import("Linear-Algebra")
| Linear-Algebra.angle(a, b) |
→ |
number |
Description
Calculates the angle between two vectors in radians.
Examples
>
let { angle } = import("Linear-Algebra");
angle([1, 0], [0, 1])
1.5707963267948966
>
let { angle } = import("Linear-Algebra");
angle([1, 0, 1], [0, 1, 0])
1.5707963267948966
let { projection } = import("Linear-Algebra")
| Linear-Algebra.projection(a, b) |
→ |
vector |
Description
Calculates the projection of vector a onto vector b.
Examples
>
let { projection } = import("Linear-Algebra");
projection([1, 2], [3, 4])
[1.32, 1.76]
>
let { projection } = import("Linear-Algebra");
projection([1, 2, 3], [4, 5, 6])
[1.662337662337662, 2.0779220779220777, 2.493506493506493]
let { collinear? } = import("Linear-Algebra")
| Linear-Algebra.collinear?(a, b) |
→ |
boolean |
Description
Checks if two vectors are collinear.
Examples
>
let { collinear? } = import("Linear-Algebra");
collinear?([1, 2], [2, 4])
true
>
let { collinear? } = import("Linear-Algebra");
collinear?([1, 2], [-2, -4])
true
>
let { collinear? } = import("Linear-Algebra");
collinear?([1, 2, 3], [2, 4, 6])
true
let { parallel? } = import("Linear-Algebra")
| Linear-Algebra.parallel?(a, b) |
→ |
boolean |
Description
Checks if two vectors are parallel.
Examples
>
let { parallel? } = import("Linear-Algebra");
parallel?([1, 2], [2, 4])
true
>
let { parallel? } = import("Linear-Algebra");
parallel?([1, 2], [-2, -4])
false
>
let { parallel? } = import("Linear-Algebra");
parallel?([1, 2, 3], [2, 4, 6])
true
>
let { parallel? } = import("Linear-Algebra");
parallel?([1, 2], [3, 4])
false
let { orthogonal? } = import("Linear-Algebra")
| Linear-Algebra.orthogonal?(a, b) |
→ |
boolean |
Description
Checks if two vectors are orthogonal.
Examples
>
let { orthogonal? } = import("Linear-Algebra");
orthogonal?([1, 0], [0, 1])
true
>
let { orthogonal? } = import("Linear-Algebra");
orthogonal?([1, 0, 1], [0, 1, 0])
true
>
let { orthogonal? } = import("Linear-Algebra");
orthogonal?([1, 2], [2, -1])
true
let { cosine-similarity } = import("Linear-Algebra")
| Linear-Algebra.cosine-similarity(a, b) |
→ |
number |
Description
Calculates the cosine similarity between two vectors. The result is a value between -1 and 1.
Examples
>
let { cosine-similarity } = import("Linear-Algebra");
cosine-similarity([1, 2], [3, 4])
0.9838699100999074
>
let { cosine-similarity } = import("Linear-Algebra");
cosine-similarity([1, 2, 3], [4, 5, 6])
0.9746318461970762
>
let { cosine-similarity } = import("Linear-Algebra");
cosine-similarity([1, 0], [0, 1])
0
let { euclidean-distance } = import("Linear-Algebra")
| Linear-Algebra.euclidean-distance(a, b) |
→ |
number |
Description
Calculates the Euclidean distance between two vectors. The result is a non-negative number.
Examples
>
let { euclidean-distance } = import("Linear-Algebra");
euclidean-distance([1, 2], [3, 4])
2.8284271247461903
>
let { euclidean-distance } = import("Linear-Algebra");
euclidean-distance([1, 2, 3], [4, 5, 6])
5.196152422706632
>
let { euclidean-distance } = import("Linear-Algebra");
euclidean-distance([1, 0], [0, 1])
1.4142135623730951
let { euclidean-norm } = import("Linear-Algebra")
| Linear-Algebra.euclidean-norm(v) |
→ |
number |
Description
Calculates the Euclidean norm (L2 norm) of a vector. The result is a non-negative number.
Arguments
| v |
vector |
Vector to calculate the norm for.
|
Examples
>
let { euclidean-norm } = import("Linear-Algebra");
euclidean-norm([1, 2])
2.23606797749979
>
let { euclidean-norm } = import("Linear-Algebra");
euclidean-norm([3, 4])
5
>
let { euclidean-norm } = import("Linear-Algebra");
euclidean-norm([1, 2, 3])
3.7416573867739413
let { manhattan-distance } = import("Linear-Algebra")
| Linear-Algebra.manhattan-distance(a, b) |
→ |
number |
Description
Calculates the Manhattan distance between two vectors. The result is a non-negative number.
Examples
>
let { manhattan-distance } = import("Linear-Algebra");
manhattan-distance([1, 2], [3, 4])
4
>
let { manhattan-distance } = import("Linear-Algebra");
manhattan-distance([1, 2, 3], [4, 5, 6])
9
>
let { manhattan-distance } = import("Linear-Algebra");
manhattan-distance([1, 0], [0, 1])
2
let { manhattan-norm } = import("Linear-Algebra")
| Linear-Algebra.manhattan-norm(v) |
→ |
number |
Description
Calculates the Manhattan norm (L1 norm) of a vector. The result is a non-negative number.
Arguments
| v |
vector |
Vector to calculate the norm for.
|
Examples
>
let { manhattan-norm } = import("Linear-Algebra");
manhattan-norm([1, 2])
3
>
let { manhattan-norm } = import("Linear-Algebra");
manhattan-norm([3, 4])
7
>
let { manhattan-norm } = import("Linear-Algebra");
manhattan-norm([1, 2, 3])
6
let { hamming-distance } = import("Linear-Algebra")
| Linear-Algebra.hamming-distance(a, b) |
→ |
integer |
Description
Calculates the Hamming distance between two vectors. The result is a non-negative integer.
Examples
>
let { hamming-distance } = import("Linear-Algebra");
hamming-distance([1, 2], [3, 4])
2
>
let { hamming-distance } = import("Linear-Algebra");
hamming-distance([1, 2, 3], [4, 5, 6])
3
>
let { hamming-distance } = import("Linear-Algebra");
hamming-distance([1, 0], [0, 1])
2
let { hamming-norm } = import("Linear-Algebra")
| Linear-Algebra.hamming-norm(v) |
→ |
integer |
Description
Calculates the Hamming norm of a vector. The result is a non-negative integer.
Arguments
| v |
vector |
Vector to calculate the norm for.
|
Examples
>
let { hamming-norm } = import("Linear-Algebra");
hamming-norm([1, 2])
2
>
let { hamming-norm } = import("Linear-Algebra");
hamming-norm([3, 4])
2
>
let { hamming-norm } = import("Linear-Algebra");
hamming-norm([1, 2, 3])
3
let { chebyshev-distance } = import("Linear-Algebra")
| Linear-Algebra.chebyshev-distance(a, b) |
→ |
number |
Description
Calculates the Chebyshev distance between two vectors. The result is a non-negative number.
Examples
>
let { chebyshev-distance } = import("Linear-Algebra");
chebyshev-distance([1, 2], [3, 4])
2
>
let { chebyshev-distance } = import("Linear-Algebra");
chebyshev-distance([1, 2, 3], [4, 5, 6])
3
>
let { chebyshev-distance } = import("Linear-Algebra");
chebyshev-distance([1, 0], [0, 1])
1
let { chebyshev-norm } = import("Linear-Algebra")
| Linear-Algebra.chebyshev-norm(v) |
→ |
number |
Description
Calculates the Chebyshev norm of a vector. The result is a non-negative number.
Arguments
| v |
vector |
Vector to calculate the norm for.
|
Examples
>
let { chebyshev-norm } = import("Linear-Algebra");
chebyshev-norm([1, 2])
2
>
let { chebyshev-norm } = import("Linear-Algebra");
chebyshev-norm([3, 4])
4
>
let { chebyshev-norm } = import("Linear-Algebra");
chebyshev-norm([1, 2, 3])
3
let { minkowski-distance } = import("Linear-Algebra")
| Linear-Algebra.minkowski-distance(a, b, p) |
→ |
number |
Description
Calculates the Minkowski distance between two vectors. The result is a non-negative number.
Examples
>
let { minkowski-distance } = import("Linear-Algebra");
minkowski-distance([1, 2], [3, 4], 2)
2.8284271247461903
>
let { minkowski-distance } = import("Linear-Algebra");
minkowski-distance([1, 2, 3], [4, 5, 6], 3)
4.3267487109222245
>
let { minkowski-distance } = import("Linear-Algebra");
minkowski-distance([1, 0], [0, 1], 1)
2
let { minkowski-norm } = import("Linear-Algebra")
| Linear-Algebra.minkowski-norm(a, b) |
→ |
number |
Description
Calculates the Minkowski norm of a vector. The result is a non-negative number.
Arguments
| a |
vector |
Vector to calculate the norm for.
|
| b |
number |
Order of the norm (p).
|
Examples
>
let { minkowski-norm } = import("Linear-Algebra");
minkowski-norm([1, 2], 2)
2.23606797749979
>
let { minkowski-norm } = import("Linear-Algebra");
minkowski-norm([3, 4], 3)
4.497941445275415
>
let { minkowski-norm } = import("Linear-Algebra");
minkowski-norm([1, 2, 3], 4)
3.1463462836457885
let { cov } = import("Linear-Algebra")
| Linear-Algebra.cov(a, b) |
→ |
number |
Description
Calculates the covariance between two vectors. The result is a number.
Examples
>
let { cov } = import("Linear-Algebra");
cov([1, 2], [3, 4])
0.25
>
let { cov } = import("Linear-Algebra");
cov([1, 2, 3], [4, 5, 6])
0.6666666666666666
>
let { cov } = import("Linear-Algebra");
cov([1, 0], [0, 1])
-0.25
let { corr } = import("Linear-Algebra")
| Linear-Algebra.corr(a, b) |
→ |
number |
Description
Calculates the correlation between two vectors. The result is a number between -1 and 1.
Examples
>
let { corr } = import("Linear-Algebra");
corr([1, 2], [3, 4])
1
>
let { corr } = import("Linear-Algebra");
corr([1, 2, 3], [4, 5, 6])
1
>
let { corr } = import("Linear-Algebra");
corr([1, 0], [0, 1])
-1
let { spearman-corr } = import("Linear-Algebra")
| Linear-Algebra.spearman-corr(a, b) |
→ |
number |
Description
Calculates the Spearman rank correlation between two vectors. The result is a number between -1 and 1.
Examples
>
let { spearman-corr } = import("Linear-Algebra");
spearman-corr([1, 2], [3, 4])
0.9999999999999998
>
let { spearman-corr } = import("Linear-Algebra");
spearman-corr([1, 2, 3], [4, 5, 6])
0.9999999999999998
>
let { spearman-corr } = import("Linear-Algebra");
spearman-corr([1, 0], [0, 1])
-0.9999999999999998
let { pearson-corr } = import("Linear-Algebra")
| Linear-Algebra.pearson-corr(a, b) |
→ |
number |
Description
Calculates the Pearson correlation between two vectors. The result is a number between -1 and 1.
Examples
>
let { pearson-corr } = import("Linear-Algebra");
pearson-corr([1, 2], [3, 4])
0.9999999999999998
>
let { pearson-corr } = import("Linear-Algebra");
pearson-corr([1, 2, 3], [4, 5, 6])
0.9999999999999998
>
let { pearson-corr } = import("Linear-Algebra");
pearson-corr([1, 0], [0, 1])
-0.9999999999999998
let { kendall-tau } = import("Linear-Algebra")
| Linear-Algebra.kendall-tau(a, b) |
→ |
number |
Description
Calculates the Kendall Tau rank correlation coefficient between two vectors. The result is a number between -1 and 1.
Examples
>
let { kendall-tau } = import("Linear-Algebra");
kendall-tau([1, 2], [3, 4])
1
>
let { kendall-tau } = import("Linear-Algebra");
kendall-tau([1, 2, 3], [4, 5, 6])
1
>
let { kendall-tau } = import("Linear-Algebra");
kendall-tau([1, 0], [0, 1])
-1
let { autocorrelation } = import("Linear-Algebra")
| Linear-Algebra.autocorrelation(a, b) |
→ |
vector |
Description
Calculates the autocorrelation of a vector. The result is a vector of autocorrelation coefficients.
Arguments
| a |
vector |
Vector to calculate the autocorrelation for.
|
| b |
integer |
Lag value for the autocorrelation.
|
Examples
>
let { autocorrelation } = import("Linear-Algebra");
autocorrelation([1, 2, 3], -2)
-0.5
>
let { autocorrelation } = import("Linear-Algebra");
autocorrelation([1, 2, 3], -1)
0
>
let { autocorrelation } = import("Linear-Algebra");
autocorrelation([1, 2, 3], 0)
1
>
let { autocorrelation } = import("Linear-Algebra");
autocorrelation([1, 2, 3], 1)
0
>
let { autocorrelation } = import("Linear-Algebra");
autocorrelation([1, 2, 3], 2)
-0.5
let { cross-correlation } = import("Linear-Algebra")
| Linear-Algebra.cross-correlation(a, b, lag) |
→ |
vector |
Description
Calculates the cross-correlation between two vectors. The result is a vector of cross-correlation coefficients.
Examples
>
let { cross-correlation } = import("Linear-Algebra");
cross-correlation([1, 2, 3], [4, 5, 6], -2)
0
>
let { cross-correlation } = import("Linear-Algebra");
cross-correlation([1, 2, 3], [4, 5, 6], -1)
1
>
let { cross-correlation } = import("Linear-Algebra");
cross-correlation([1, 2, 3], [4, 5, 6], 0)
1
>
let { cross-correlation } = import("Linear-Algebra");
cross-correlation([1, 2, 3], [4, 5, 6], 1)
1
>
let { cross-correlation } = import("Linear-Algebra");
cross-correlation([1, 2, 3], [4, 5, 6], 2)
0
let { rref } = import("Linear-Algebra")
| Linear-Algebra.rref(m) |
→ |
matrix |
Description
Calculates the Reduced Row Echelon Form (RREF) of a matrix.
Arguments
| m |
matrix |
Matrix to calculate the RREF for.
|
Examples
>
let { rref } = import("Linear-Algebra");
rref([[1, 2], [3, 4]])
[ 1 0 ]
[ 0 1 ]
>
let { rref } = import("Linear-Algebra");
rref([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
[ 1 0 -1 ]
[ 0 1 2 ]
[ 0 0 0 ]
>
let { rref } = import("Linear-Algebra");
rref([[1, 2, 3], [7, 8, 9], [4, 5, 7]])
[ 1 0 0 ]
[ 0 1 0 ]
[ 0 0 1 ]
let { solve } = import("Linear-Algebra")
| Linear-Algebra.solve(a, b) |
→ |
vector |
Description
Solves a system of linear equations represented by a matrix and a vector.
Examples
>
let { solve } = import("Linear-Algebra");
solve([
[2, 1, -1, 1],
[4, 5, -3, 2],
[6, -2, 5, -3],
[8, 3, 2, 4]
], [5, 10, 2, 17])
[1.519607843137255, -0.17647058823529416, -0.5294117647058822, 1.6078431372549018]
>
let { solve } = import("Linear-Algebra"); solve([[2, 0, 0], [3, 1, 0], [4, 5, 6]], [4, 5, 38])
[2, -1, 5.833333333333333]
>
let { solve } = import("Linear-Algebra"); solve([[2, 3], [1, -1]], [8, 2])
[2.8, 0.8]
let { to-polar } = import("Linear-Algebra")
| Linear-Algebra.to-polar(vector) |
→ |
vector |
Description
Converts a 2D vector to polar coordinates.
Arguments
| vector |
vector |
2D Vector to convert.
|
Examples
>
let { to-polar } = import("Linear-Algebra");
to-polar([1, 2])
[2.23606797749979, 1.1071487177940904]
>
let { to-polar } = import("Linear-Algebra");
to-polar([3, 4])
[5, 0.9272952180016122]
let { from-polar } = import("Linear-Algebra")
| Linear-Algebra.from-polar(polar) |
→ |
vector |
Description
Converts polar coordinates to a 2D vector.
Arguments
| polar |
vector |
Polar coordinates to convert.
|
Examples
>
let { from-polar } = import("Linear-Algebra");
from-polar([1, PI / 4])
[0.7071067811865476, 0.7071067811865475]
>
let { from-polar } = import("Linear-Algebra");
from-polar([1, 0])
[1, 0]
>
let { from-polar } = import("Linear-Algebra");
from-polar([1, -PI / 2])
[6.123233995736766e-17, -1]
let { mul } = import("Matrix")
Description
Multiplies two matrices using standard matrix multiplication based on dot products of rows and columns.
Examples
>
let { mul } = import("Matrix");
mul([[1, 2], [3, 4]], [[5, 6], [7, 8]])
[ 19 22 ]
[ 43 50 ]
>
let { mul } = import("Matrix");
mul([[1, 2, 3], [4, 5, 6]], [[7, 8], [9, 10], [11, 12]])
[ 58 64 ]
[ 139 154 ]
let { det } = import("Matrix")
Description
Calculates the determinant of a square matrix.
Arguments
| m |
matrix |
The matrix to calculate the determinant of.
|
Examples
>
let { det } = import("Matrix");
det([[1, 2], [3, 4]])
-2
>
let { det } = import("Matrix");
det([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
6.661338147750939e-16
let { inv } = import("Matrix")
Description
Calculates the inverse of a square matrix.
Arguments
| m |
matrix |
The matrix to calculate the inverse of.
|
Examples
>
let { inv } = import("Matrix");
inv([[1, 2], [3, 4]])
[ -2 1 ]
[ 1.5 -0.5 ]
>
let { inv } = import("Matrix");
inv([[1, 2, 3], [4, 5, 7], [7, 8, 10]])
[ -1.999999999999999 1.3333333333333326 -0.33333333333333315 ]
[ 2.9999999999999982 -3.6666666666666643 1.6666666666666656 ]
[ -0.9999999999999994 1.999999999999999 -0.9999999999999994 ]
let { adj } = import("Matrix")
Description
Calculates the adjugate of a square matrix.
Arguments
| m |
matrix |
The matrix to calculate the adjugate of.
|
Examples
>
let { adj } = import("Matrix");
adj([[1, 2], [3, 4]])
[ 4 -2 ]
[ -3 1 ]
>
let { adj } = import("Matrix");
adj([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
[ -3 6 -3 ]
[ 6 -12 6 ]
[ -3 6 -3 ]
>
let { adj } = import("Matrix");
adj([[1, 2, 3], [7, 8, 9], [4, 5, 6]])
[ 3 3 -6 ]
[ -6 -6 12 ]
[ 3 3 -6 ]
let { cofactor } = import("Matrix")
Description
Calculates the cofactor of a square matrix.
Arguments
| m |
matrix |
The matrix to calculate the cofactor of.
|
Examples
>
let { cofactor } = import("Matrix");
cofactor([[1, 2], [3, 4]])
[ 4 -3 ]
[ -2 1 ]
>
let { cofactor } = import("Matrix");
cofactor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
[ -3 6 -3 ]
[ 6 -12 6 ]
[ -3 6 -3 ]
>
let { cofactor } = import("Matrix");
cofactor([[1, 2, 3], [7, 8, 9], [4, 5, 6]])
[ 3 -6 3 ]
[ 3 -6 3 ]
[ -6 12 -6 ]
let { minor } = import("Matrix")
| Matrix.minor(m, row, col) |
→ |
matrix |
Description
Calculates the minor of a square matrix.
Arguments
| m |
matrix |
The matrix to calculate the minor of.
|
| row |
integer |
The row index of the element to calculate the minor for.
|
| col |
integer |
The column index of the element to calculate the minor for.
|
Examples
>
let { minor } = import("Matrix");
minor([[1, 2], [3, 4]], 0, 1)
[ 3 ]
>
let { minor } = import("Matrix");
minor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1, 1)
[ 1 3 ]
[ 7 9 ]
let { trace } = import("Matrix")
Description
Calculates the trace of a square matrix.
Arguments
| m |
matrix |
The matrix to calculate the trace of.
|
Examples
>
let { trace } = import("Matrix");
trace([[1, 2], [3, 4]])
5
>
let { trace } = import("Matrix");
trace([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
15
let { symmetric? } = import("Matrix")
Description
Checks if a matrix is symmetric.
Arguments
| m |
matrix |
The matrix to check for symmetry.
|
Examples
>
let { symmetric? } = import("Matrix");
symmetric?([[1, 2], [2, 1]])
true
>
let { symmetric? } = import("Matrix");
symmetric?([[1, 2, 3], [2, 1, 4], [3, 4, 1]])
true
let { triangular? } = import("Matrix")
Description
Checks if a matrix is triangular.
Arguments
| m |
matrix |
The matrix to check for triangularity.
|
Examples
>
let { triangular? } = import("Matrix");
triangular?([[2, 0], [0, 1]])
true
>
let { triangular? } = import("Matrix");
triangular?([[1, 2, 3], [0, 4, 5], [0, 0, 6]])
true
let { upper-triangular? } = import("Matrix")
| Matrix.upper-triangular?(m) |
→ |
boolean |
Description
Checks if a matrix is upper triangular.
Arguments
| m |
matrix |
The matrix to check for upper triangularity.
|
Examples
>
let { upper-triangular? } = import("Matrix");
upper-triangular?([[1, 2], [0, 3]])
true
>
let { upper-triangular? } = import("Matrix");
upper-triangular?([[1, 2, 3], [0, 4, 5], [0, 0, 6]])
true
let { lower-triangular? } = import("Matrix")
| Matrix.lower-triangular?(m) |
→ |
boolean |
Description
Checks if a matrix is lower triangular.
Arguments
| m |
matrix |
The matrix to check for lower triangularity.
|
Examples
>
let { lower-triangular? } = import("Matrix");
lower-triangular?([[1, 0], [2, 3]])
true
>
let { lower-triangular? } = import("Matrix");
lower-triangular?([[1, 0, 0], [2, 3, 0], [4, 5, 6]])
true
let { diagonal? } = import("Matrix")
Description
Checks if a matrix is diagonal.
Arguments
| m |
matrix |
The matrix to check for diagonal property.
|
Examples
>
let { diagonal? } = import("Matrix");
diagonal?([[1, 0], [0, 2]])
true
>
let { diagonal? } = import("Matrix");
diagonal?([[1, 0, 0], [0, 2, 0], [0, 0, 3]])
true
>
let { diagonal? } = import("Matrix");
diagonal?([[1, 0, 0], [2, 2, 2], [0, 0, 3]])
false
let { square? } = import("Matrix")
Description
Checks if a matrix is square.
Arguments
| m |
matrix |
The matrix to check for square property.
|
Examples
>
let { square? } = import("Matrix");
square?([[1, 2], [3, 4]])
true
>
let { square? } = import("Matrix");
square?([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
true
>
let { square? } = import("Matrix");
square?([[1, 2, 3], [4, 5, 6]])
false
let { orthogonal? } = import("Matrix")
Description
Checks if a matrix is orthogonal.
Arguments
| m |
matrix |
The matrix to check for orthogonality.
|
Examples
>
let { orthogonal? } = import("Matrix");
orthogonal?([[1, 0], [0, 1]])
true
>
let { orthogonal? } = import("Matrix");
orthogonal?([[1, 0], [0, -1]])
true
>
let { orthogonal? } = import("Matrix");
orthogonal?([[1, 2], [3, 4]])
false
let { identity? } = import("Matrix")
Description
Checks if a matrix is an identity matrix.
Arguments
| m |
matrix |
The matrix to check for identity property.
|
Examples
>
let { identity? } = import("Matrix");
identity?([[1, 0], [0, 1]])
true
>
let { identity? } = import("Matrix");
identity?([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
true
>
let { identity? } = import("Matrix");
identity?([[1, 0, 0], [0, 1, 0], [0, 0, 0]])
false
let { invertible? } = import("Matrix")
Description
Checks if a matrix is invertible.
Arguments
| m |
matrix |
The matrix to check for invertibility.
|
Examples
>
let { invertible? } = import("Matrix");
invertible?([[1, 2], [3, 4]])
true
>
let { invertible? } = import("Matrix");
invertible?([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
false
>
let { invertible? } = import("Matrix");
invertible?([[1, 2], [2, 4]])
false
let { hilbert } = import("Matrix")
Description
Generates a Hilbert matrix of size n.
Arguments
| n |
integer |
The size of the Hilbert matrix.
|
Examples
>
let { hilbert } = import("Matrix");
hilbert(3)
[ 1 0.5 0.3333333333333333 ]
[ 0.5 0.3333333333333333 0.25 ]
[ 0.3333333333333333 0.25 0.2 ]
>
let { hilbert } = import("Matrix");
hilbert(4)
[ 1 0.5 0.3333333333333333 0.25 ]
[ 0.5 0.3333333333333333 0.25 0.2 ]
[ 0.3333333333333333 0.25 0.2 0.16666666666666666 ]
[ 0.25 0.2 0.16666666666666666 0.14285714285714285 ]
let { vandermonde } = import("Matrix")
| Matrix.vandermonde(v) |
→ |
matrix |
Description
Generates a Vandermonde matrix from a vector.
Arguments
| v |
vector |
The vector to generate the Vandermonde matrix from.
|
Examples
>
let { vandermonde } = import("Matrix");
vandermonde([1, 2, 3])
[ 1 1 1 ]
[ 1 2 4 ]
[ 1 3 9 ]
>
let { vandermonde } = import("Matrix");
vandermonde([1, 0, 1])
[ 1 1 1 ]
[ 1 0 0 ]
[ 1 1 1 ]
let { band } = import("Matrix")
| Matrix.band(n, lband, uband) |
→ |
matrix |
Description
Generates a banded matrix of size n with lower band index lband and upper band index uband.
Arguments
| n |
integer |
The size of the banded matrix.
|
| lband |
integer |
The lower band index.
|
| uband |
integer |
The upper band index.
|
Examples
>
let { band } = import("Matrix");
band(3, 1, 1)
[ 1 1 0 ]
[ 1 1 1 ]
[ 0 1 1 ]
>
let { band } = import("Matrix");
band(4, 1, 2)
[ 1 1 1 0 ]
[ 1 1 1 1 ]
[ 0 1 1 1 ]
[ 0 0 1 1 ]
let { banded? } = import("Matrix")
| Matrix.banded?(m, lband, uband) |
→ |
boolean |
Description
Checks if a matrix is banded with lower band index lband and upper band index uband.
Arguments
| m |
matrix |
The matrix to check for banded property.
|
| lband |
integer |
The lower band index.
|
| uband |
integer |
The upper band index.
|
Examples
>
let { banded? } = import("Matrix");
banded?([
[1, 1, 1, 0],
[1, 1, 1, 1],
[1, 1, 1, 1],
[0, 1, 1, 1],
], 2, 2)
true
>
let { banded? } = import("Matrix");
banded?([
[1, 1, 1, 0],
[1, 1, 1, 1],
[1, 1, 1, 1],
[0, 1, 1, 1],
], 1, 1)
false
let { rank } = import("Matrix")
Description
Calculates the rank of a matrix using Gaussian elimination.
Arguments
| m |
matrix |
The matrix to calculate the rank of.
|
Examples
>
let { rank } = import("Matrix");
rank([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
3
>
let { rank } = import("Matrix");
rank([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
2
>
let { rank } = import("Matrix");
rank([[2, 4, 6], [3, 6, 9], [4, 8, 12]])
1
let { frobenius-norm } = import("Matrix")
| Matrix.frobenius-norm(m) |
→ |
number |
Description
Calculates the Frobenius norm of a matrix.
Arguments
| m |
matrix |
The matrix to calculate the Frobenius norm of.
|
Examples
>
let { frobenius-norm } = import("Matrix");
frobenius-norm([[1, 2], [3, 4]])
5.477225575051661
>
let { frobenius-norm } = import("Matrix");
frobenius-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
16.881943016134134
let { one-norm } = import("Matrix")
Description
Calculates the one-norm (column norm) of a matrix.
Arguments
| m |
matrix |
The matrix to calculate the one-norm of.
|
Examples
>
let { one-norm } = import("Matrix");
one-norm([[1, 2], [3, 4]])
6
>
let { one-norm } = import("Matrix");
one-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
18
let { inf-norm } = import("Matrix")
Description
Calculates the infinity norm of a matrix.
Arguments
| m |
matrix |
The matrix to calculate the infinity norm of.
|
Examples
>
let { inf-norm } = import("Matrix");
inf-norm([[1, 2], [3, 4]])
7
>
let { inf-norm } = import("Matrix");
inf-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
24
let { max-norm } = import("Matrix")
Description
Calculates the max norm of a matrix.
Arguments
| m |
matrix |
The matrix to calculate the max norm of.
|
Examples
>
let { max-norm } = import("Matrix");
max-norm([[1, 2], [3, 4]])
4
>
let { max-norm } = import("Matrix");
max-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
9
let { abundant-seq } = import("Number-Theory")
| Number-Theory.abundant-seq(length) |
→ |
Array<integer> |
Description
Generates the abundant numbers up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { abundant-seq } = import("Number-Theory");
abundant-seq(1)
[12]
>
let { abundant-seq } = import("Number-Theory");
abundant-seq(5)
[12, 18, 20, 24, 30]
let { abundant-take-while } = import("Number-Theory")
| Number-Theory.abundant-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the abundant numbers while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { abundant-take-while } = import("Number-Theory");
abundant-take-while(-> $ < 100)
[
12,
18,
20,
24,
30,
36,
40,
42,
48,
54,
56,
60,
66,
70,
72,
78,
80,
84,
88,
90,
96
]
let { abundant-nth } = import("Number-Theory")
| Number-Theory.abundant-nth(n) |
→ |
integer |
Description
Generates the nth term of the abundant numbers.
Arguments
| n |
integer |
The index of the number in the sequence.
|
Examples
>
let { abundant-nth } = import("Number-Theory");
abundant-nth(1)
12
>
let { abundant-nth } = import("Number-Theory");
abundant-nth(5)
30
let { abundant? } = import("Number-Theory")
| Number-Theory.abundant?(n) |
→ |
boolean |
Description
Checks if a number is abundant.
Examples
>
let { abundant? } = import("Number-Theory");
abundant?(12)
true
>
let { abundant? } = import("Number-Theory");
abundant?(15)
false
let { arithmetic-seq } = import("Number-Theory")
| Number-Theory.arithmetic-seq(start, step, length) |
→ |
Array<integer> |
Description
Generates the arithmetic sequence for a given start, step, and length.
Arguments
| start |
number |
The starting term of the sequence.
|
| step |
number |
The common difference of the sequence.
|
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { arithmetic-seq } = import("Number-Theory");
arithmetic-seq(3, 2, 2)
[3, 5]
>
let { arithmetic-seq } = import("Number-Theory");
arithmetic-seq(2, 3, 2)
[2, 5]
>
let { arithmetic-seq } = import("Number-Theory");
arithmetic-seq(1, 2, 2)
[1, 3]
>
let { arithmetic-seq } = import("Number-Theory");
arithmetic-seq(1, 1.5, 12)
[
1,
2.5,
4,
5.5,
7,
8.5,
10,
11.5,
13,
14.5,
16,
17.5
]
let { arithmetic-take-while } = import("Number-Theory")
| Number-Theory.arithmetic-take-while(start, step, takeWhile) |
→ |
Array<integer> |
Description
Generates the arithmetic sequence while a condition is met.
Arguments
| start |
number |
The starting term of the sequence.
|
| step |
number |
The common difference of the sequence.
|
| takeWhile |
function |
A function that takes a number and an index and returns a boolean.
|
Examples
>
let { arithmetic-take-while } = import("Number-Theory");
arithmetic-take-while(1, 0.25, -> $ < 3)
[1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75]
let { arithmetic-nth } = import("Number-Theory")
| Number-Theory.arithmetic-nth(start, step, n) |
→ |
integer |
Description
Generates the nth term of the arithmetic sequence.
Arguments
| start |
number |
The starting term of the sequence.
|
| step |
number |
The common difference of the sequence.
|
| n |
integer |
The index of the term to generate.
|
Examples
>
let { arithmetic-nth } = import("Number-Theory");
arithmetic-nth(3, 2, 2)
5
>
let { arithmetic-nth } = import("Number-Theory");
arithmetic-nth(2, 3, 2)
5
>
let { arithmetic-nth } = import("Number-Theory");
arithmetic-nth(1, 2, 2)
3
>
let { arithmetic-nth } = import("Number-Theory");
arithmetic-nth(1, 1.5, 12)
17.5
let { arithmetic? } = import("Number-Theory")
| Number-Theory.arithmetic?(start, step, n) |
→ |
boolean |
Description
Checks if a number is part of the arithmetic sequence.
Arguments
| start |
number |
The starting term of the sequence.
|
| step |
number |
The common difference of the sequence.
|
| n |
integer |
The number to check.
|
Examples
>
let { arithmetic? } = import("Number-Theory");
arithmetic?(3, 2, 2)
false
>
let { arithmetic? } = import("Number-Theory");
arithmetic?(2, 3, 2)
true
>
let { arithmetic? } = import("Number-Theory");
arithmetic?(1, 2, 2)
false
>
let { arithmetic? } = import("Number-Theory");
arithmetic?(1, 1.5, 12)
false
let { bell-seq } = import("Number-Theory")
| Number-Theory.bell-seq(length) |
→ |
Array<integer> |
| Number-Theory.bell-seq() |
→ |
Array<integer> |
Description
Generates the Bell sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate. If not provided, the default is 22 (the maximum length of the pre-calculated bell numbers).
|
Examples
>
let { bell-seq } = import("Number-Theory");
bell-seq(5)
[1, 2, 5, 15, 52]
>
let { bell-seq } = import("Number-Theory");
bell-seq(10)
[
1,
2,
5,
15,
52,
203,
877,
4140,
21147,
115975
]
>
let { bell-seq } = import("Number-Theory");
bell-seq()
[
1,
2,
5,
15,
52,
203,
877,
4140,
21147,
115975,
678570,
4213597,
27644437,
190899322,
1382958545,
10480142147,
82864869804,
682076806159,
5832742205057,
51724158235372,
474869816156751,
4506715738447323
]
let { bell-take-while } = import("Number-Theory")
| Number-Theory.bell-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the Bell sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { bell-take-while } = import("Number-Theory");
bell-take-while(-> $ < 1000)
[1, 2, 5, 15, 52, 203, 877]
let { bell-nth } = import("Number-Theory")
| Number-Theory.bell-nth(n) |
→ |
integer |
Description
Generates the nth term of the Bell sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { bell-nth } = import("Number-Theory");
bell-nth(5)
52
>
let { bell-nth } = import("Number-Theory");
bell-nth(10)
115975
let { bell? } = import("Number-Theory")
Description
Checks if a number is in the Bell sequence.
Examples
>
let { bell? } = import("Number-Theory");
bell?(1)
true
>
let { bell? } = import("Number-Theory");
bell?(27644437)
true
>
let { bell? } = import("Number-Theory");
bell?(27644436)
false
let { bernoulli-seq } = import("Number-Theory")
| Number-Theory.bernoulli-seq(length) |
→ |
Array<number> |
Description
Generates the Bernoulli sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { bernoulli-seq } = import("Number-Theory");
bernoulli-seq(5)
[1, -0.5, 0.16666666666666666, 0, -0.033333333333333305]
>
let { bernoulli-seq } = import("Number-Theory");
bernoulli-seq(10)
[
1,
-0.5,
0.16666666666666666,
0,
-0.033333333333333305,
0,
0.023809523809523662,
0,
-0.03333333333333233,
0
]
let { bernoulli-take-while } = import("Number-Theory")
| Number-Theory.bernoulli-take-while(takeWhile) |
→ |
Array<number> |
Description
Generates the Bernoulli sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { bernoulli-take-while } = import("Number-Theory");
bernoulli-take-while(-> abs($) < 100)
[
1,
-0.5,
0.16666666666666666,
0,
-0.033333333333333305,
0,
0.023809523809523662,
0,
-0.03333333333333233,
0,
0.07575757575756613,
0,
-0.2531135531134231,
0,
1.166666666664266,
0,
-7.0921568626867195,
0,
54.971177943052155,
0
]
let { bernoulli-nth } = import("Number-Theory")
| Number-Theory.bernoulli-nth(n) |
→ |
number |
Description
Generates the nth term of the Bernoulli sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { bernoulli-nth } = import("Number-Theory");
bernoulli-nth(5)
-0.033333333333333305
>
let { bernoulli-nth } = import("Number-Theory");
bernoulli-nth(10)
0
>
let { bernoulli-nth } = import("Number-Theory");
bernoulli-nth(23)
6192.123185143487
let { catalan-seq } = import("Number-Theory")
| Number-Theory.catalan-seq(length) |
→ |
Array<integer> |
| Number-Theory.catalan-seq() |
→ |
Array<integer> |
Description
Generates the Catalan sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate. If not provided, the default is 30 (the maximum length of the pre-calculated catalan numbers).
|
Examples
>
let { catalan-seq } = import("Number-Theory");
catalan-seq(5)
[1, 2, 5, 14, 42]
>
let { catalan-seq } = import("Number-Theory");
catalan-seq(10)
[
1,
2,
5,
14,
42,
132,
429,
1430,
4862,
16796
]
>
let { catalan-seq } = import("Number-Theory");
catalan-seq()
[
1,
2,
5,
14,
42,
132,
429,
1430,
4862,
16796,
58786,
208012,
742900,
2674440,
9694845,
35357670,
129644790,
477638700,
1767263190,
6564120420,
24466267020,
91482563640,
343059613650,
1289904147324,
4861946401452,
18367353072152,
69533550916004,
263747951750360,
1002242216651368,
3814986502092304
]
let { catalan-take-while } = import("Number-Theory")
| Number-Theory.catalan-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the Catalan sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { catalan-take-while } = import("Number-Theory");
catalan-take-while(-> $ < 1000)
[1, 2, 5, 14, 42, 132, 429]
let { catalan-nth } = import("Number-Theory")
| Number-Theory.catalan-nth(n) |
→ |
integer |
Description
Generates the nth term of the Catalan sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { catalan-nth } = import("Number-Theory");
catalan-nth(5)
42
>
let { catalan-nth } = import("Number-Theory");
catalan-nth(10)
16796
let { catalan? } = import("Number-Theory")
| Number-Theory.catalan?(n) |
→ |
boolean |
Description
Determines if a number is in the Catalan sequence.
Examples
>
let { catalan? } = import("Number-Theory");
catalan?(5)
true
>
let { catalan? } = import("Number-Theory");
catalan?(10)
false
let { collatz-seq } = import("Number-Theory")
| Number-Theory.collatz-seq(start) |
→ |
Array<integer> |
Description
Generates the collatz sequence starting from a given integer.
Arguments
| start |
integer |
The starting integer for the collatz sequence.
|
Examples
>
let { collatz-seq } = import("Number-Theory");
collatz-seq(3)
[3, 10, 5, 16, 8, 4, 2, 1]
>
let { collatz-seq } = import("Number-Theory");
collatz-seq(11)
[
11,
34,
17,
52,
26,
13,
40,
20,
10,
5,
16,
8,
4,
2,
1
]
let { composite-seq } = import("Number-Theory")
| Number-Theory.composite-seq(length) |
→ |
Array<integer> |
Description
Generates the composite sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { composite-seq } = import("Number-Theory");
composite-seq(1)
[4]
>
let { composite-seq } = import("Number-Theory");
composite-seq(2)
[4, 6]
>
let { composite-seq } = import("Number-Theory");
composite-seq(10)
[
4,
6,
8,
9,
10,
12,
14,
15,
16,
18
]
let { composite-take-while } = import("Number-Theory")
| Number-Theory.composite-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the composite sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { composite-take-while } = import("Number-Theory");
composite-take-while(-> $ < 50)
[
4,
6,
8,
9,
10,
12,
14,
15,
16,
18,
20,
21,
22,
24,
25,
26,
27,
28,
30,
32,
33,
34,
35,
36,
38,
39,
40,
42,
44,
45,
46,
48,
49
]
let { composite-nth } = import("Number-Theory")
| Number-Theory.composite-nth(n) |
→ |
integer |
Description
Generates the nth term of the composite sequence.
Arguments
| n |
integer |
The index of the composite number to retrieve.
|
Examples
>
let { composite-nth } = import("Number-Theory");
composite-nth(1)
4
>
let { composite-nth } = import("Number-Theory");
composite-nth(2)
6
>
let { composite-nth } = import("Number-Theory");
composite-nth(10)
18
let { composite? } = import("Number-Theory")
| Number-Theory.composite?(n) |
→ |
boolean |
Description
Determines if a number is composite.
Examples
>
let { composite? } = import("Number-Theory");
composite?(4)
true
>
let { composite? } = import("Number-Theory");
composite?(5)
false
>
let { composite? } = import("Number-Theory");
composite?(11)
false
let { deficient-seq } = import("Number-Theory")
| Number-Theory.deficient-seq(length) |
→ |
Array<integer> |
Description
Generates the deficient numbers up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { deficient-seq } = import("Number-Theory");
deficient-seq(1)
[1]
>
let { deficient-seq } = import("Number-Theory");
deficient-seq(5)
[1, 2, 3, 4, 5]
let { deficient-take-while } = import("Number-Theory")
| Number-Theory.deficient-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the deficient numbers while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { deficient-take-while } = import("Number-Theory");
deficient-take-while(-> $ < 100)
[
1,
2,
3,
4,
5,
7,
8,
9,
10,
11,
13,
14,
15,
16,
17,
19,
21,
22,
23,
25,
26,
27,
29,
31,
32,
33,
34,
35,
37,
38,
39,
41,
43,
44,
45,
46,
47,
49,
50,
51,
52,
53,
55,
57,
58,
59,
61,
62,
63,
64,
65,
67,
68,
69,
71,
73,
74,
75,
76,
77,
79,
81,
82,
83,
85,
86,
87,
89,
91,
92,
93,
94,
95,
97,
98,
99
]
let { deficient-nth } = import("Number-Theory")
| Number-Theory.deficient-nth(n) |
→ |
integer |
Description
Generates the nth term of the deficient numbers.
Arguments
| n |
integer |
The index of the number in the sequence.
|
Examples
>
let { deficient-nth } = import("Number-Theory");
deficient-nth(5)
5
>
let { deficient-nth } = import("Number-Theory");
deficient-nth(12)
14
let { deficient? } = import("Number-Theory")
| Number-Theory.deficient?(n) |
→ |
boolean |
Description
Checks if a number is deficient.
Examples
>
let { deficient? } = import("Number-Theory");
deficient?(12)
false
>
let { deficient? } = import("Number-Theory");
deficient?(15)
true
let { factorial-seq } = import("Number-Theory")
| Number-Theory.factorial-seq(length) |
→ |
Array<integer> |
| Number-Theory.factorial-seq() |
→ |
Array<integer> |
Description
Generates the factorial sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate. If not provided, the default is 19 (the maximum length of the pre-calculated factorial numbers).
|
Examples
>
let { factorial-seq } = import("Number-Theory");
factorial-seq(1)
[1]
>
let { factorial-seq } = import("Number-Theory");
factorial-seq(2)
[1, 1]
>
let { factorial-seq } = import("Number-Theory");
factorial-seq(3)
[1, 1, 2]
>
let { factorial-seq } = import("Number-Theory");
factorial-seq(4)
[1, 1, 2, 6]
>
let { factorial-seq } = import("Number-Theory");
factorial-seq(5)
[1, 1, 2, 6, 24]
>
let { factorial-seq } = import("Number-Theory");
factorial-seq(10)
[
1,
1,
2,
6,
24,
120,
720,
5040,
40320,
362880
]
let { factorial-take-while } = import("Number-Theory")
| Number-Theory.factorial-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the factorial sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { factorial-take-while } = import("Number-Theory");
factorial-take-while(-> $ < 1000)
[1, 1, 2, 6, 24, 120, 720]
let { factorial-nth } = import("Number-Theory")
| Number-Theory.factorial-nth(n) |
→ |
integer |
Description
Generates the nth term of the factorial sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { factorial-nth } = import("Number-Theory");
factorial-nth(1)
1
>
let { factorial-nth } = import("Number-Theory");
factorial-nth(2)
1
>
let { factorial-nth } = import("Number-Theory");
factorial-nth(3)
2
>
let { factorial-nth } = import("Number-Theory");
factorial-nth(4)
6
>
let { factorial-nth } = import("Number-Theory");
factorial-nth(5)
24
>
let { factorial-nth } = import("Number-Theory");
factorial-nth(10)
362880
let { factorial? } = import("Number-Theory")
| Number-Theory.factorial?(n) |
→ |
boolean |
Description
Checks if a number is in the factorial sequence.
Examples
>
let { factorial? } = import("Number-Theory");
factorial?(1)
true
>
let { factorial? } = import("Number-Theory");
factorial?(2)
true
>
let { factorial? } = import("Number-Theory");
factorial?(3)
false
>
let { factorial? } = import("Number-Theory");
factorial?(4)
false
>
let { factorial? } = import("Number-Theory");
factorial?(5)
false
>
let { factorial? } = import("Number-Theory");
factorial?(6)
true
>
let { factorial? } = import("Number-Theory");
factorial?(7)
false
>
let { factorial? } = import("Number-Theory");
factorial?(8)
false
>
let { factorial? } = import("Number-Theory");
factorial?(9)
false
>
let { factorial? } = import("Number-Theory");
factorial?(3628800)
true
let { fibonacci-seq } = import("Number-Theory")
| Number-Theory.fibonacci-seq(length) |
→ |
Array<integer> |
| Number-Theory.fibonacci-seq() |
→ |
Array<integer> |
Description
Generates the fibonacci sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate. If not provided, the default is 79 (the maximum length of the pre-calculated Fibonacci numbers).
|
Examples
>
let { fibonacci-seq } = import("Number-Theory");
fibonacci-seq(1)
[0]
>
let { fibonacci-seq } = import("Number-Theory");
fibonacci-seq(2)
[0, 1]
>
let { fibonacci-seq } = import("Number-Theory");
fibonacci-seq()
[
0,
1,
1,
2,
3,
5,
8,
13,
21,
34,
55,
89,
144,
233,
377,
610,
987,
1597,
2584,
4181,
6765,
10946,
17711,
28657,
46368,
75025,
121393,
196418,
317811,
514229,
832040,
1346269,
2178309,
3524578,
5702887,
9227465,
14930352,
24157817,
39088169,
63245986,
102334155,
165580141,
267914296,
433494437,
701408733,
1134903170,
1836311903,
2971215073,
4807526976,
7778742049,
12586269025,
20365011074,
32951280099,
53316291173,
86267571272,
139583862445,
225851433717,
365435296162,
591286729879,
956722026041,
1548008755920,
2504730781961,
4052739537881,
6557470319842,
10610209857723,
17167680177565,
27777890035288,
44945570212853,
72723460248141,
117669030460994,
190392490709135,
308061521170129,
498454011879264,
806515533049393,
1304969544928657,
2111485077978050,
3416454622906707,
5527939700884757,
8944394323791464
]
let { fibonacci-take-while } = import("Number-Theory")
| Number-Theory.fibonacci-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the fibonacci sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { fibonacci-take-while } = import("Number-Theory");
fibonacci-take-while(-> $ < 100)
[
0,
1,
1,
2,
3,
5,
8,
13,
21,
34,
55,
89
]
let { fibonacci-nth } = import("Number-Theory")
| Number-Theory.fibonacci-nth(n) |
→ |
integer |
Description
Generates the nth term of the fibonacci sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { fibonacci-nth } = import("Number-Theory");
fibonacci-nth(5)
3
>
let { fibonacci-nth } = import("Number-Theory");
fibonacci-nth(50)
7778742049
let { fibonacci? } = import("Number-Theory")
| Number-Theory.fibonacci?(n) |
→ |
boolean |
Description
Determines if a number is in the fibonacci sequence.
Examples
>
let { fibonacci? } = import("Number-Theory");
fibonacci?(0)
true
>
let { fibonacci? } = import("Number-Theory");
fibonacci?(1)
true
>
let { fibonacci? } = import("Number-Theory");
fibonacci?(2)
true
>
let { fibonacci? } = import("Number-Theory");
fibonacci?(3)
true
>
let { fibonacci? } = import("Number-Theory");
fibonacci?(4)
false
>
let { fibonacci? } = import("Number-Theory");
fibonacci?(5)
true
>
let { fibonacci? } = import("Number-Theory");
fibonacci?(6)
false
>
let { fibonacci? } = import("Number-Theory");
fibonacci?(7)
false
>
let { fibonacci? } = import("Number-Theory");
fibonacci?(8)
true
>
let { fibonacci? } = import("Number-Theory");
fibonacci?(9)
false
let { geometric-seq } = import("Number-Theory")
| Number-Theory.geometric-seq(start, ratio, length) |
→ |
Array<integer> |
Description
Generates the geometric sequence for a given start, ratio, and length.
Arguments
| start |
number |
The starting term of the sequence.
|
| ratio |
number |
The common ratio of the sequence.
|
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { geometric-seq } = import("Number-Theory");
geometric-seq(3, 2, 2)
[3, 6]
>
let { geometric-seq } = import("Number-Theory");
geometric-seq(2, 3, 2)
[2, 6]
>
let { geometric-seq } = import("Number-Theory");
geometric-seq(1, 2, 2)
[1, 2]
>
let { geometric-seq } = import("Number-Theory");
geometric-seq(1, 1.5, 12)
[
1,
1.5,
2.25,
3.375,
5.0625,
7.59375,
11.390625,
17.0859375,
25.62890625,
38.443359375,
57.6650390625,
86.49755859375
]
let { geometric-take-while } = import("Number-Theory")
| Number-Theory.geometric-take-while(start, ratio, takeWhile) |
→ |
Array<integer> |
Description
Generates the geometric sequence while a condition is met.
Arguments
| start |
number |
The starting term of the sequence.
|
| ratio |
number |
The common ratio of the sequence.
|
| takeWhile |
function |
A function that takes a number and an index and returns a boolean.
|
Examples
>
let { geometric-take-while } = import("Number-Theory");
geometric-take-while(1, 1.5, -> $ < 10)
[1, 1.5, 2.25, 3.375, 5.0625, 7.59375]
let { geometric-nth } = import("Number-Theory")
| Number-Theory.geometric-nth(start, ratio, n) |
→ |
integer |
Description
Generates the nth term of the geometric sequence.
Arguments
| start |
number |
The starting term of the sequence.
|
| ratio |
number |
The common ratio of the sequence.
|
| n |
integer |
The index of the term to generate.
|
Examples
>
let { geometric-nth } = import("Number-Theory");
geometric-nth(3, 2, 2)
6
>
let { geometric-nth } = import("Number-Theory");
geometric-nth(2, 3, 2)
6
>
let { geometric-nth } = import("Number-Theory");
geometric-nth(1, 2, 2)
2
>
let { geometric-nth } = import("Number-Theory");
geometric-nth(1, 1.5, 4)
3.375
let { geometric? } = import("Number-Theory")
| Number-Theory.geometric?(start, ratio, n) |
→ |
boolean |
Description
Checks if a number is in the geometric sequence.
Arguments
| start |
number |
The starting term of the sequence.
|
| ratio |
number |
The common ratio of the sequence.
|
| n |
number |
The number to check.
|
Examples
>
let { geometric? } = import("Number-Theory");
geometric?(1, 2, 1)
true
>
let { geometric? } = import("Number-Theory");
geometric?(2, 3, 2)
true
>
let { geometric? } = import("Number-Theory");
geometric?(3, 2, 2)
false
>
let { geometric? } = import("Number-Theory");
geometric?(1, 1.5, 2.25)
true
>
let { geometric? } = import("Number-Theory");
geometric?(1, 1.5, -4)
false
let { golomb-seq } = import("Number-Theory")
| Number-Theory.golomb-seq(length) |
→ |
Array<integer> |
Description
Generates the Golomb sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { golomb-seq } = import("Number-Theory");
golomb-seq(5)
[1, 2, 2, 3, 3]
>
let { golomb-seq } = import("Number-Theory");
golomb-seq(20)
[
1,
2,
2,
3,
3,
4,
4,
4,
5,
5,
5,
6,
6,
6,
6,
7,
7,
7,
7,
8
]
let { golomb-take-while } = import("Number-Theory")
| Number-Theory.golomb-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the Golomb sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { golomb-take-while } = import("Number-Theory");
golomb-take-while(-> $ <= 10)
[
1,
2,
2,
3,
3,
4,
4,
4,
5,
5,
5,
6,
6,
6,
6,
7,
7,
7,
7,
8,
8,
8,
8,
9,
9,
9,
9,
9,
10,
10,
10,
10,
10
]
let { golomb-nth } = import("Number-Theory")
| Number-Theory.golomb-nth(n) |
→ |
integer |
Description
Generates the nth term of the Golomb sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { golomb-nth } = import("Number-Theory");
golomb-nth(5)
3
>
let { golomb-nth } = import("Number-Theory");
golomb-nth(1000)
86
let { golomb? } = import("Number-Theory")
Description
Checks if a number is in the Golomb sequence.
Examples
>
let { golomb? } = import("Number-Theory");
golomb?(1)
true
>
let { golomb? } = import("Number-Theory");
golomb?(2)
true
>
let { golomb? } = import("Number-Theory");
golomb?(3345)
true
>
let { golomb? } = import("Number-Theory");
golomb?(67867864)
true
let { happy-seq } = import("Number-Theory")
| Number-Theory.happy-seq(length) |
→ |
Array<integer> |
| Number-Theory.happy-seq() |
→ |
Array<integer> |
Description
Generates the happy sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate. If not provided, the default is 20 (the maximum length of the pre-calculated happy numbers).
|
Examples
>
let { happy-seq } = import("Number-Theory");
happy-seq(1)
[1]
>
let { happy-seq } = import("Number-Theory");
happy-seq(2)
[1, 7]
>
let { happy-seq } = import("Number-Theory");
happy-seq(20)
[
1,
7,
10,
13,
19,
23,
28,
31,
32,
44,
49,
68,
70,
79,
82,
86,
91,
94,
97,
100
]
let { happy-take-while } = import("Number-Theory")
| Number-Theory.happy-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the happy sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { happy-take-while } = import("Number-Theory");
happy-take-while(-> $ < 100)
[
1,
7,
10,
13,
19,
23,
28,
31,
32,
44,
49,
68,
70,
79,
82,
86,
91,
94,
97
]
let { happy-nth } = import("Number-Theory")
| Number-Theory.happy-nth(n) |
→ |
integer |
Description
Generates the nth term of the happy sequence.
Arguments
| n |
integer |
The index of the happy number to return.
|
Examples
>
let { happy-nth } = import("Number-Theory");
happy-nth(1)
1
>
let { happy-nth } = import("Number-Theory");
happy-nth(2)
7
>
let { happy-nth } = import("Number-Theory");
happy-nth(20)
100
let { happy? } = import("Number-Theory")
Description
Determines if a number is a happy number.
Examples
>
let { happy? } = import("Number-Theory");
happy?(1)
true
>
let { happy? } = import("Number-Theory");
happy?(2)
false
>
let { happy? } = import("Number-Theory");
happy?(100)
true
let { juggler-seq } = import("Number-Theory")
| Number-Theory.juggler-seq(start) |
→ |
Array<integer> |
Description
Generates the Juggler sequence starting from a given integer.
Arguments
| start |
integer |
The starting integer for the Juggler sequence.
|
Examples
>
let { juggler-seq } = import("Number-Theory");
juggler-seq(3)
[3, 5, 11, 36, 6, 2, 1]
>
let { juggler-seq } = import("Number-Theory");
juggler-seq(5)
[5, 11, 36, 6, 2, 1]
let { look-and-say-seq } = import("Number-Theory")
| Number-Theory.look-and-say-seq(length) |
→ |
Array<string> |
Description
Generates the Look-and-Say sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { look-and-say-seq } = import("Number-Theory");
look-and-say-seq(5)
[
"1",
"11",
"21",
"1211",
"111221"
]
let { look-and-say-take-while } = import("Number-Theory")
| Number-Theory.look-and-say-take-while(takeWhile) |
→ |
Array<string> |
Description
Generates the Look-and-Say sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes a string and an index and returns a boolean.
|
Examples
>
let { look-and-say-take-while } = import("Number-Theory");
look-and-say-take-while((term, index) -> count(term) < 10)
[
"1",
"11",
"21",
"1211",
"111221",
"312211",
"13112221"
]
>
let { look-and-say-take-while } = import("Number-Theory");
look-and-say-take-while(-> $2 <= 10)
[
"1",
"11",
"21",
"1211",
"111221",
"312211",
"13112221",
"1113213211",
"31131211131221",
"13211311123113112211",
"11131221133112132113212221"
]
let { look-and-say-nth } = import("Number-Theory")
| Number-Theory.look-and-say-nth(n) |
→ |
string |
Description
Generates the nth term of the Look-and-Say sequence.
Arguments
| n |
integer |
The index of the term in the sequence.
|
Examples
>
let { look-and-say-nth } = import("Number-Theory");
look-and-say-nth(5)
"111221"
let { look-and-say? } = import("Number-Theory")
| Number-Theory.look-and-say?(term) |
→ |
boolean |
Description
Checks if a string is a valid Look-and-Say term.
Arguments
| term |
string |
The term to check.
|
Examples
>
let { look-and-say? } = import("Number-Theory");
look-and-say?("111221")
true
>
let { look-and-say? } = import("Number-Theory");
look-and-say?("123")
false
let { lucas-seq } = import("Number-Theory")
| Number-Theory.lucas-seq(length) |
→ |
Array<integer> |
| Number-Theory.lucas-seq() |
→ |
Array<integer> |
Description
Generates the lucas sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate. If not provided, the default is 77 (the maximum length of the pre-calculated Lucas numbers).
|
Examples
>
let { lucas-seq } = import("Number-Theory");
lucas-seq(1)
[2]
>
let { lucas-seq } = import("Number-Theory");
lucas-seq(2)
[2, 1]
>
let { lucas-seq } = import("Number-Theory");
lucas-seq()
[
2,
1,
3,
4,
7,
11,
18,
29,
47,
76,
123,
199,
322,
521,
843,
1364,
2207,
3571,
5778,
9349,
15127,
24476,
39603,
64079,
103682,
167761,
271443,
439204,
710647,
1149851,
1860498,
3010349,
4870847,
7881196,
12752043,
20633239,
33385282,
54018521,
87403803,
141422324,
228826127,
370248451,
599074578,
969323029,
1568397607,
2537720636,
4106118243,
6643838879,
10749957122,
17393796001,
28143753123,
45537549124,
73681302247,
119218851371,
192900153618,
312119004989,
505019158607,
817138163596,
1322157322203,
2139295485799,
3461452808002,
5600748293801,
9062201101803,
14662949395604,
23725150497407,
38388099893011,
62113250390418,
100501350283429,
162614600673847,
263115950957276,
425730551631123,
688846502588399,
1114577054219522,
1803423556807921,
2918000611027443,
4721424167835364,
7639424778862807
]
let { lucas-take-while } = import("Number-Theory")
| Number-Theory.lucas-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the lucas sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { lucas-take-while } = import("Number-Theory");
lucas-take-while(-> $ < 100)
[
2,
1,
3,
4,
7,
11,
18,
29,
47,
76
]
let { lucas-nth } = import("Number-Theory")
| Number-Theory.lucas-nth(n) |
→ |
integer |
Description
Generates the nth term of the lucas sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { lucas-nth } = import("Number-Theory");
lucas-nth(1)
2
>
let { lucas-nth } = import("Number-Theory");
lucas-nth(2)
1
>
let { lucas-nth } = import("Number-Theory");
lucas-nth(10)
76
let { lucas? } = import("Number-Theory")
Description
Determines if a number is in the lucas sequence.
Examples
>
let { lucas? } = import("Number-Theory");
lucas?(1)
true
>
let { lucas? } = import("Number-Theory");
lucas?(2)
true
>
let { lucas? } = import("Number-Theory");
lucas?(10)
false
let { lucky-seq } = import("Number-Theory")
| Number-Theory.lucky-seq(length) |
→ |
Array<integer> |
Description
Generates the lucky sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { lucky-seq } = import("Number-Theory");
lucky-seq(1)
[1]
>
let { lucky-seq } = import("Number-Theory");
lucky-seq(2)
[1, 3]
>
let { lucky-seq } = import("Number-Theory");
lucky-seq(20)
[
1,
3,
7,
9,
13,
15,
21,
25,
31,
33,
37,
43,
49,
51,
63,
67,
69,
73,
75,
79
]
let { lucky-take-while } = import("Number-Theory")
| Number-Theory.lucky-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the lucky sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { lucky-take-while } = import("Number-Theory");
lucky-take-while(-> $ < 100)
[
1,
3,
7,
9,
13,
15,
21,
25,
31,
33,
37,
43,
49,
51,
63,
67,
69,
73,
75,
79,
87,
93,
99
]
let { lucky-nth } = import("Number-Theory")
| Number-Theory.lucky-nth(n) |
→ |
integer |
Description
Generates the nth term of the lucky sequence.
Arguments
| n |
integer |
The position in the sequence.
|
Examples
>
let { lucky-nth } = import("Number-Theory");
lucky-nth(1)
1
>
let { lucky-nth } = import("Number-Theory");
lucky-nth(2)
3
>
let { lucky-nth } = import("Number-Theory");
lucky-nth(20)
79
let { lucky? } = import("Number-Theory")
Description
Checks if a number is a lucky number.
Examples
>
let { lucky? } = import("Number-Theory");
lucky?(4)
false
>
let { lucky? } = import("Number-Theory");
lucky?(7)
true
>
let { lucky? } = import("Number-Theory");
lucky?(33)
true
let { mersenne-seq } = import("Number-Theory")
| Number-Theory.mersenne-seq(length) |
→ |
Array<integer> |
| Number-Theory.mersenne-seq() |
→ |
Array<integer> |
Description
Generates the Mersenne sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate. If not provided, the default is 9 (the maximum length of the pre-calculated mersenne numbers).
|
Examples
>
let { mersenne-seq } = import("Number-Theory");
mersenne-seq(1)
[3]
>
let { mersenne-seq } = import("Number-Theory");
mersenne-seq(5)
[3, 7, 31, 127, 2047]
>
let { mersenne-seq } = import("Number-Theory");
mersenne-seq()
[
3,
7,
31,
127,
2047,
8191,
131071,
524287,
2147483647
]
let { mersenne-take-while } = import("Number-Theory")
| Number-Theory.mersenne-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the Mersenne sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { mersenne-take-while } = import("Number-Theory");
mersenne-take-while(-> $ < 1000)
[3, 7, 31, 127]
let { mersenne-nth } = import("Number-Theory")
| Number-Theory.mersenne-nth(n) |
→ |
integer |
Description
Generates the nth term of the Mersenne sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { mersenne-nth } = import("Number-Theory");
mersenne-nth(1)
3
>
let { mersenne-nth } = import("Number-Theory");
mersenne-nth(5)
2047
let { mersenne? } = import("Number-Theory")
| Number-Theory.mersenne?(n) |
→ |
boolean |
Description
Checks if a number is in the Mersenne sequence.
Examples
>
let { mersenne? } = import("Number-Theory");
mersenne?(3)
true
>
let { mersenne? } = import("Number-Theory");
mersenne?(4)
false
>
let { mersenne? } = import("Number-Theory");
mersenne?(7)
true
let { padovan-seq } = import("Number-Theory")
| Number-Theory.padovan-seq(length) |
→ |
Array<integer> |
Description
Generates the Padovan sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { padovan-seq } = import("Number-Theory");
padovan-seq(5)
[1, 1, 1, 2, 2]
>
let { padovan-seq } = import("Number-Theory");
padovan-seq(10)
[
1,
1,
1,
2,
2,
3,
4,
5,
7,
9
]
>
let { padovan-seq } = import("Number-Theory");
padovan-seq(20)
[
1,
1,
1,
2,
2,
3,
4,
5,
7,
9,
12,
16,
21,
28,
37,
49,
65,
86,
114,
151
]
let { padovan-take-while } = import("Number-Theory")
| Number-Theory.padovan-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the Padovan sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { padovan-take-while } = import("Number-Theory");
padovan-take-while(-> $ < 1000)
[
1,
1,
1,
2,
2,
3,
4,
5,
7,
9,
12,
16,
21,
28,
37,
49,
65,
86,
114,
151,
200,
265,
351,
465,
616,
816
]
let { padovan-nth } = import("Number-Theory")
| Number-Theory.padovan-nth(n) |
→ |
integer |
Description
Generates the nth term of the Padovan sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { padovan-nth } = import("Number-Theory");
padovan-nth(5)
2
>
let { padovan-nth } = import("Number-Theory");
padovan-nth(10)
9
>
let { padovan-nth } = import("Number-Theory");
padovan-nth(20)
151
let { padovan? } = import("Number-Theory")
| Number-Theory.padovan?(n) |
→ |
boolean |
Description
Checks if a number is in the Padovan sequence.
Examples
>
let { padovan? } = import("Number-Theory");
padovan?(1)
true
>
let { padovan? } = import("Number-Theory");
padovan?(265)
true
>
let { padovan? } = import("Number-Theory");
padovan?(6)
false
let { partition-seq } = import("Number-Theory")
| Number-Theory.partition-seq(length) |
→ |
Array<integer> |
| Number-Theory.partition-seq() |
→ |
Array<integer> |
Description
Generates the partition numbers up to a specified length. If no length is provided, it defaults to 299 (the maximum length of the pre-calculated partition numbers).
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { partition-seq } = import("Number-Theory");
partition-seq(1)
[1]
>
let { partition-seq } = import("Number-Theory");
partition-seq(10)
[
1,
2,
3,
5,
7,
11,
15,
22,
30,
42
]
>
let { partition-seq } = import("Number-Theory");
partition-seq()
[
1,
2,
3,
5,
7,
11,
15,
22,
30,
42,
56,
77,
101,
135,
176,
231,
297,
385,
490,
627,
792,
1002,
1255,
1575,
1958,
2436,
3010,
3718,
4565,
5604,
6842,
8349,
10143,
12310,
14883,
17977,
21637,
26015,
31185,
37338,
44583,
53174,
63261,
75175,
89134,
105558,
124754,
147273,
173525,
204226,
239943,
281589,
329931,
386155,
451276,
526823,
614154,
715220,
831820,
966467,
1121505,
1300156,
1505499,
1741630,
2012558,
2323520,
2679689,
3087735,
3554345,
4087968,
4697205,
5392783,
6185689,
7089500,
8118264,
9289091,
10619863,
12132164,
13848650,
15796476,
18004327,
20506255,
23338469,
26543660,
30167357,
34262962,
38887673,
44108109,
49995925,
56634173,
64112359,
72533807,
82010177,
92669720,
104651419,
118114304,
133230930,
150198136,
169229875,
190569292,
214481126,
241265379,
271248950,
304801365,
342325709,
384276336,
431149389,
483502844,
541946240,
607163746,
679903203,
761002156,
851376628,
952050665,
1064144451,
1188908248,
1327710076,
1482074143,
1653668665,
1844349560,
2056148051,
2291320912,
2552338241,
2841940500,
3163127352,
3519222692,
3913864295,
4351078600,
4835271870,
5371315400,
5964539504,
6620830889,
7346629512,
8149040695,
9035836076,
10015581680,
11097645016,
12292341831,
13610949895,
15065878135,
16670689208,
18440293320,
20390982757,
22540654445,
24908858009,
27517052599,
30388671978,
33549419497,
37027355200,
40853235313,
45060624582,
49686288421,
54770336324,
60356673280,
66493182097,
73232243759,
80630964769,
88751778802,
97662728555,
107438159466,
118159068427,
129913904637,
142798995930,
156919475295,
172389800255,
189334822579,
207890420102,
228204732751,
250438925115,
274768617130,
301384802048,
330495499613,
362326859895,
397125074750,
435157697830,
476715857290,
522115831195,
571701605655,
625846753120,
684957390936,
749474411781,
819876908323,
896684817527,
980462880430,
1071823774337,
1171432692373,
1280011042268,
1398341745571,
1527273599625,
1667727404093,
1820701100652,
1987276856363,
2168627105469,
2366022741845,
2580840212973,
2814570987591,
3068829878530,
3345365983698,
3646072432125,
3972999029388,
4328363658647,
4714566886083,
5134205287973,
5590088317495,
6085253859260,
6622987708040,
7206841706490,
7840656226137,
8528581302375,
9275102575355,
10085065885767,
10963707205259,
11916681236278,
12950095925895,
14070545699287,
15285151248481,
16601598107914,
18028182516671,
19573856161145,
21248279009367,
23061871173849,
25025873760111,
27152408925615,
29454549941750,
31946390696157,
34643126322519,
37561133582570,
40718063627362,
44132934884255,
47826239745920,
51820051838712,
56138148670947,
60806135438329,
65851585970275,
71304185514919,
77195892663512,
83561103925871,
90436839668817,
97862933703585,
105882246722733,
114540884553038,
123888443077259,
133978259344888,
144867692496445,
156618412527946,
169296722391554,
182973889854026,
197726516681672,
213636919820625,
230793554364681,
249291451168559,
269232701252579,
290726957916112,
313891991306665,
338854264248680,
365749566870782,
394723676655357,
425933084409356,
459545750448675,
495741934760846,
534715062908609,
576672674947168,
621837416509615,
670448123060170,
722760953690372,
779050629562167,
839611730366814,
904760108316360,
974834369944625,
1050197489931117,
1131238503938606,
1218374349844333,
1312051800816215,
1412749565173450,
1520980492851175,
1637293969337171,
1762278433057269,
1896564103591584,
2040825852575075,
2195786311682516,
2362219145337711,
2540952590045698,
2732873183547535,
2938929793929555,
3160137867148997,
3397584011986773,
3652430836071053,
3925922161489422,
4219388528587095,
4534253126900886,
4872038056472084,
5234371069753672,
5622992691950605,
6039763882095515,
6486674127079088,
6965850144195831,
7479565078510584,
8030248384943040,
8620496275465025
]
let { partition-take-while } = import("Number-Theory")
| Number-Theory.partition-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the partition numbers while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { partition-take-while } = import("Number-Theory");
partition-take-while(-> $ < 1000)
[
1,
2,
3,
5,
7,
11,
15,
22,
30,
42,
56,
77,
101,
135,
176,
231,
297,
385,
490,
627,
792
]
let { partition-nth } = import("Number-Theory")
| Number-Theory.partition-nth(n) |
→ |
integer |
Description
Generates the nth term of the partition numbers.
Arguments
| n |
integer |
The index of the partition number to generate.
|
Examples
>
let { partition-nth } = import("Number-Theory");
partition-nth(1)
1
>
let { partition-nth } = import("Number-Theory");
partition-nth(5)
7
let { partition? } = import("Number-Theory")
| Number-Theory.partition?(n) |
→ |
boolean |
Description
Checks if a number is in the partition numbers.
Examples
>
let { partition? } = import("Number-Theory");
partition?(0)
false
>
let { partition? } = import("Number-Theory");
partition?(1)
true
>
let { partition? } = import("Number-Theory");
partition?(2)
true
>
let { partition? } = import("Number-Theory");
partition?(3)
true
>
let { partition? } = import("Number-Theory");
partition?(4)
false
>
let { partition? } = import("Number-Theory");
partition?(5)
true
let { pell-seq } = import("Number-Theory")
| Number-Theory.pell-seq(length) |
→ |
Array<integer> |
| Number-Theory.pell-seq() |
→ |
Array<integer> |
Description
Generates the Pell sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate. If not provided, the default is 42 (the maximum length of the pre-calculated Pell numbers).
|
Examples
>
let { pell-seq } = import("Number-Theory");
pell-seq(5)
[1, 2, 5, 12, 29]
>
let { pell-seq } = import("Number-Theory");
pell-seq(10)
[
1,
2,
5,
12,
29,
70,
169,
408,
985,
2378
]
>
let { pell-seq } = import("Number-Theory");
pell-seq()
[
1,
2,
5,
12,
29,
70,
169,
408,
985,
2378,
5741,
13860,
33461,
80782,
195025,
470832,
1136689,
2744210,
6625109,
15994428,
38613965,
93222358,
225058681,
543339720,
1311738121,
3166815962,
7645370045,
18457556052,
44560482149,
107578520350,
259717522849,
627013566048,
1513744654945,
3654502875938,
8822750406821,
21300003689580,
51422757785981,
124145519261542,
299713796309065,
723573111879672,
1746860020068409,
4217293152016490
]
let { pell-take-while } = import("Number-Theory")
| Number-Theory.pell-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the Pell sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { pell-take-while } = import("Number-Theory");
pell-take-while(-> $ < 1000)
[
1,
2,
5,
12,
29,
70,
169,
408,
985
]
let { pell-nth } = import("Number-Theory")
| Number-Theory.pell-nth(n) |
→ |
integer |
Description
Generates the nth term of the Pell sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { pell-nth } = import("Number-Theory");
pell-nth(5)
29
>
let { pell-nth } = import("Number-Theory");
pell-nth(10)
2378
>
let { pell-nth } = import("Number-Theory");
pell-nth(20)
15994428
let { pell? } = import("Number-Theory")
Description
Checks if a number is a Pell number.
Examples
>
let { pell? } = import("Number-Theory");
pell?(1)
true
>
let { pell? } = import("Number-Theory");
pell?(470832)
true
>
let { pell? } = import("Number-Theory");
pell?(10)
false
let { perfect-seq } = import("Number-Theory")
| Number-Theory.perfect-seq(length) |
→ |
Array<integer> |
| Number-Theory.perfect-seq() |
→ |
Array<integer> |
Description
Generates the perfect numbers up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate. If no length is provided, it defaults to 7 (the maximum length of the pre-calculated perfect numbers).
|
Examples
>
let { perfect-seq } = import("Number-Theory");
perfect-seq(1)
[6]
>
let { perfect-seq } = import("Number-Theory");
perfect-seq(5)
[6, 28, 496, 8128, 33550336]
>
let { perfect-seq } = import("Number-Theory");
perfect-seq()
[6, 28, 496, 8128, 33550336, 8589869056, 137438691328]
let { perfect-take-while } = import("Number-Theory")
| Number-Theory.perfect-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the perfect numbers while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { perfect-take-while } = import("Number-Theory");
perfect-take-while(-> $ < 1000)
[6, 28, 496]
let { perfect-nth } = import("Number-Theory")
| Number-Theory.perfect-nth(n) |
→ |
integer |
Description
Generates the nth term of the perfect numbers.
Arguments
| n |
integer |
The index of the perfect number to generate.
|
Examples
>
let { perfect-nth } = import("Number-Theory");
perfect-nth(1)
6
>
let { perfect-nth } = import("Number-Theory");
perfect-nth(5)
33550336
let { perfect? } = import("Number-Theory")
| Number-Theory.perfect?(n) |
→ |
boolean |
Description
Checks if a number is in the perfect numbers.
Examples
>
let { perfect? } = import("Number-Theory");
perfect?(0)
false
>
let { perfect? } = import("Number-Theory");
perfect?(1)
false
>
let { perfect? } = import("Number-Theory");
perfect?(2)
false
>
let { perfect? } = import("Number-Theory");
perfect?(3)
false
>
let { perfect? } = import("Number-Theory");
perfect?(4)
false
>
let { perfect? } = import("Number-Theory");
perfect?(5)
false
>
let { perfect? } = import("Number-Theory");
perfect?(6)
true
>
let { perfect? } = import("Number-Theory");
perfect?(7)
false
>
let { perfect? } = import("Number-Theory");
perfect?(8)
false
>
let { perfect? } = import("Number-Theory");
perfect?(9)
false
let { perfect-square-seq } = import("Number-Theory")
| Number-Theory.perfect-square-seq(length) |
→ |
Array<integer> |
Description
Generates the perfect square numbers up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { perfect-square-seq } = import("Number-Theory");
perfect-square-seq(5)
[1, 4, 9, 16, 25]
>
let { perfect-square-seq } = import("Number-Theory");
perfect-square-seq(20)
[
1,
4,
9,
16,
25,
36,
49,
64,
81,
100,
121,
144,
169,
196,
225,
256,
289,
324,
361,
400
]
let { perfect-square-take-while } = import("Number-Theory")
| Number-Theory.perfect-square-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the perfect square numbers while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { perfect-square-take-while } = import("Number-Theory");
perfect-square-take-while(-> $ <= 100)
[
1,
4,
9,
16,
25,
36,
49,
64,
81,
100
]
let { perfect-square-nth } = import("Number-Theory")
| Number-Theory.perfect-square-nth(n) |
→ |
integer |
Description
Generates the nth term of the perfect square numbers.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { perfect-square-nth } = import("Number-Theory");
perfect-square-nth(1)
1
>
let { perfect-square-nth } = import("Number-Theory");
perfect-square-nth(5)
25
let { perfect-square? } = import("Number-Theory")
| Number-Theory.perfect-square?(n) |
→ |
boolean |
Description
Checks if a number is a perfect square.
Examples
>
let { perfect-square? } = import("Number-Theory");
perfect-square?(16)
true
>
let { perfect-square? } = import("Number-Theory");
perfect-square?(20)
false
let { perfect-cube-seq } = import("Number-Theory")
| Number-Theory.perfect-cube-seq(length) |
→ |
Array<integer> |
Description
Generates the perfect cube numbers up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { perfect-cube-seq } = import("Number-Theory");
perfect-cube-seq(5)
[1, 8, 27, 64, 125]
>
let { perfect-cube-seq } = import("Number-Theory");
perfect-cube-seq(20)
[
1,
8,
27,
64,
125,
216,
343,
512,
729,
1000,
1331,
1728,
2197,
2744,
3375,
4096,
4913,
5832,
6859,
8000
]
let { perfect-cube-take-while } = import("Number-Theory")
| Number-Theory.perfect-cube-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the perfect cube numbers while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { perfect-cube-take-while } = import("Number-Theory");
perfect-cube-take-while(-> $ <= 100)
[1, 8, 27, 64]
let { perfect-cube-nth } = import("Number-Theory")
| Number-Theory.perfect-cube-nth(n) |
→ |
integer |
Description
Generates the nth term of the perfect cube numbers.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { perfect-cube-nth } = import("Number-Theory");
perfect-cube-nth(1)
1
>
let { perfect-cube-nth } = import("Number-Theory");
perfect-cube-nth(5)
125
let { perfect-cube? } = import("Number-Theory")
| Number-Theory.perfect-cube?(n) |
→ |
boolean |
Description
Checks if a number is in the perfect cube numbers.
Examples
>
let { perfect-cube? } = import("Number-Theory");
perfect-cube?(7)
false
>
let { perfect-cube? } = import("Number-Theory");
perfect-cube?(8)
true
>
let { perfect-cube? } = import("Number-Theory");
perfect-cube?(9)
false
let { perfect-power-seq } = import("Number-Theory")
| Number-Theory.perfect-power-seq(length) |
→ |
Array<integer> |
Description
Generates the perfect power numbers up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { perfect-power-seq } = import("Number-Theory");
perfect-power-seq(5)
[1, 4, 8, 9, 16]
>
let { perfect-power-seq } = import("Number-Theory");
perfect-power-seq(20)
[
1,
4,
8,
9,
16,
25,
27,
32,
36,
49,
64,
81,
100,
121,
125,
128,
144,
169,
196,
216
]
let { perfect-power-take-while } = import("Number-Theory")
| Number-Theory.perfect-power-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the perfect power numbers while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { perfect-power-take-while } = import("Number-Theory");
perfect-power-take-while(-> $ <= 100)
[
1,
4,
8,
9,
16,
25,
27,
32,
36,
49,
64,
81,
100
]
let { perfect-power-nth } = import("Number-Theory")
| Number-Theory.perfect-power-nth(n) |
→ |
integer |
Description
Generates the nth term of the perfect power numbers.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { perfect-power-nth } = import("Number-Theory");
perfect-power-nth(3)
8
>
let { perfect-power-nth } = import("Number-Theory");
perfect-power-nth(15)
125
let { perfect-power? } = import("Number-Theory")
| Number-Theory.perfect-power?(n) |
→ |
boolean |
Description
Checks if a number is in the perfect power numbers.
Examples
>
let { perfect-power? } = import("Number-Theory");
perfect-power?(7)
false
>
let { perfect-power? } = import("Number-Theory");
perfect-power?(8)
true
>
let { perfect-power? } = import("Number-Theory");
perfect-power?(9)
true
>
let { perfect-power? } = import("Number-Theory");
perfect-power?(10)
false
let { polygonal-seq } = import("Number-Theory")
| Number-Theory.polygonal-seq(sides, length) |
→ |
Array<integer> |
Description
Generates the polygonal sequence for a given number of sides and length.
Examples
>
let { polygonal-seq } = import("Number-Theory");
polygonal-seq(3, 2)
[1, 3]
>
let { polygonal-seq } = import("Number-Theory");
polygonal-seq(4, 2)
[1, 4]
>
let { polygonal-seq } = import("Number-Theory");
polygonal-seq(5, 3)
[1, 5, 12]
>
let { polygonal-seq } = import("Number-Theory");
polygonal-seq(6, 5)
[1, 6, 15, 28, 45]
>
let { polygonal-seq } = import("Number-Theory");
polygonal-seq(100, 10)
[
1,
100,
297,
592,
985,
1476,
2065,
2752,
3537,
4420
]
let { polygonal-take-while } = import("Number-Theory")
| Number-Theory.polygonal-take-while(sides, takeWhile) |
→ |
Array<integer> |
Description
Generates the polygonal sequence while a condition is met.
Arguments
| sides |
integer |
The number of sides of the polygon.
|
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
| a |
integer |
| b |
function |
Examples
>
let { polygonal-take-while } = import("Number-Theory");
polygonal-take-while(15, -> $ < 1000)
[
1,
15,
42,
82,
135,
201,
280,
372,
477,
595,
726,
870
]
let { polygonal-nth } = import("Number-Theory")
| Number-Theory.polygonal-nth(sides, n) |
→ |
integer |
Description
Generates the nth term of the polygonal sequence.
Examples
>
let { polygonal-nth } = import("Number-Theory");
polygonal-nth(3, 9)
45
>
let { polygonal-nth } = import("Number-Theory");
polygonal-nth(4, 5)
25
>
let { polygonal-nth } = import("Number-Theory");
polygonal-nth(5, 5)
35
let { polygonal? } = import("Number-Theory")
| Number-Theory.polygonal?(sides, n) |
→ |
boolean |
Description
Checks if a number is in the polygonal sequence.
Examples
>
let { polygonal? } = import("Number-Theory");
polygonal?(3, 10)
true
>
let { polygonal? } = import("Number-Theory");
polygonal?(3, 9)
false
>
let { polygonal? } = import("Number-Theory");
polygonal?(4, 10000)
true
>
let { polygonal? } = import("Number-Theory");
polygonal?(4, 1000)
false
>
let { polygonal? } = import("Number-Theory");
polygonal?(6, 45)
true
let { prime-seq } = import("Number-Theory")
| Number-Theory.prime-seq(length) |
→ |
Array<integer> |
Description
Generates the prime sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { prime-seq } = import("Number-Theory");
prime-seq(1)
[2]
>
let { prime-seq } = import("Number-Theory");
prime-seq(2)
[2, 3]
>
let { prime-seq } = import("Number-Theory");
prime-seq(10)
[
2,
3,
5,
7,
11,
13,
17,
19,
23,
29
]
let { prime-take-while } = import("Number-Theory")
| Number-Theory.prime-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the prime sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { prime-take-while } = import("Number-Theory");
prime-take-while(-> $ < 50)
[
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47
]
let { prime-nth } = import("Number-Theory")
| Number-Theory.prime-nth(n) |
→ |
integer |
Description
Generates the nth term of the prime sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { prime-nth } = import("Number-Theory");
prime-nth(1)
2
>
let { prime-nth } = import("Number-Theory");
prime-nth(2)
3
>
let { prime-nth } = import("Number-Theory");
prime-nth(10)
29
let { prime? } = import("Number-Theory")
Description
Determines if a number is prime.
Examples
>
let { prime? } = import("Number-Theory");
prime?(1)
false
>
let { prime? } = import("Number-Theory");
prime?(2)
true
>
let { prime? } = import("Number-Theory");
prime?(3)
true
>
let { prime? } = import("Number-Theory");
prime?(4)
false
>
let { prime? } = import("Number-Theory");
prime?(997)
true
>
let { prime? } = import("Number-Theory");
prime?(1001)
false
let { recaman-seq } = import("Number-Theory")
| Number-Theory.recaman-seq(length) |
→ |
Array<integer> |
Description
Generates the Recaman sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { recaman-seq } = import("Number-Theory");
recaman-seq(5)
[0, 1, 3, 6, 2]
>
let { recaman-seq } = import("Number-Theory");
recaman-seq(10)
[
0,
1,
3,
6,
2,
7,
13,
20,
12,
21
]
>
let { recaman-seq } = import("Number-Theory");
recaman-seq(20)
[
0,
1,
3,
6,
2,
7,
13,
20,
12,
21,
11,
22,
10,
23,
9,
24,
8,
25,
43,
62
]
let { recaman-take-while } = import("Number-Theory")
| Number-Theory.recaman-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the Recaman sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { recaman-take-while } = import("Number-Theory");
recaman-take-while(-> $ < 10)
[0, 1, 3, 6, 2, 7]
let { recaman-nth } = import("Number-Theory")
| Number-Theory.recaman-nth(n) |
→ |
integer |
Description
Generates the nth term of the Recaman sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { recaman-nth } = import("Number-Theory");
recaman-nth(5)
2
>
let { recaman-nth } = import("Number-Theory");
recaman-nth(10)
21
>
let { recaman-nth } = import("Number-Theory");
recaman-nth(20)
62
let { recaman? } = import("Number-Theory")
| Number-Theory.recaman?(n) |
→ |
boolean |
Description
Checks if a number is in the Recaman sequence.
Examples
>
let { recaman? } = import("Number-Theory");
recaman?(5)
true
>
let { recaman? } = import("Number-Theory");
recaman?(10)
true
>
let { recaman? } = import("Number-Theory");
recaman?(20)
true
let { sylvester-seq } = import("Number-Theory")
| Number-Theory.sylvester-seq(length) |
→ |
Array<integer> |
| Number-Theory.sylvester-seq() |
→ |
Array<integer> |
Description
Generates the Sylvester sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate. If not provided, the default is 6 (the maximum length of the pre-calculated Sylvester numbers).
|
Examples
>
let { sylvester-seq } = import("Number-Theory");
sylvester-seq(5)
[2, 6, 42, 1806, 3263442]
>
let { sylvester-seq } = import("Number-Theory");
sylvester-seq()
[2, 6, 42, 1806, 3263442, 10650056950806]
>
let { sylvester-seq } = import("Number-Theory");
sylvester-seq()
[2, 6, 42, 1806, 3263442, 10650056950806]
let { sylvester-take-while } = import("Number-Theory")
| Number-Theory.sylvester-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the Sylvester sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { sylvester-take-while } = import("Number-Theory");
sylvester-take-while(-> $ < 100000)
[2, 6, 42, 1806]
let { sylvester-nth } = import("Number-Theory")
| Number-Theory.sylvester-nth(n) |
→ |
integer |
Description
Generates the nth term of the Sylvester sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { sylvester-nth } = import("Number-Theory");
sylvester-nth(1)
2
>
let { sylvester-nth } = import("Number-Theory");
sylvester-nth(5)
3263442
let { sylvester? } = import("Number-Theory")
| Number-Theory.sylvester?(n) |
→ |
boolean |
Description
Checks if a number is in the Sylvester sequence.
Examples
>
let { sylvester? } = import("Number-Theory");
sylvester?(2)
true
>
let { sylvester? } = import("Number-Theory");
sylvester?(3)
false
>
let { sylvester? } = import("Number-Theory");
sylvester?(6)
true
let { thue-morse-seq } = import("Number-Theory")
| Number-Theory.thue-morse-seq(length) |
→ |
Array<integer> |
Description
Generates the Thue-Morse sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { thue-morse-seq } = import("Number-Theory");
thue-morse-seq(5)
[0, 1, 1, 0, 1]
>
let { thue-morse-seq } = import("Number-Theory");
thue-morse-seq(10)
[
0,
1,
1,
0,
1,
0,
0,
1,
1,
0
]
>
let { thue-morse-seq } = import("Number-Theory");
thue-morse-seq(20)
[
0,
1,
1,
0,
1,
0,
0,
1,
1,
0,
0,
1,
0,
1,
1,
0,
1,
0,
0,
1
]
let { thue-morse-take-while } = import("Number-Theory")
| Number-Theory.thue-morse-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the Thue-Morse sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { thue-morse-take-while } = import("Number-Theory");
thue-morse-take-while(-> $2 < 10)
[
0,
1,
1,
0,
1,
0,
0,
1,
1,
0
]
let { thue-morse-nth } = import("Number-Theory")
| Number-Theory.thue-morse-nth(n) |
→ |
integer |
Description
Generates the nth term of the Thue-Morse sequence.
Arguments
| n |
integer |
The index of the term in the sequence.
|
Examples
>
let { thue-morse-nth } = import("Number-Theory");
thue-morse-nth(5)
1
>
let { thue-morse-nth } = import("Number-Theory");
thue-morse-nth(10)
0
>
let { thue-morse-nth } = import("Number-Theory");
thue-morse-nth(20)
1
let { thue-morse? } = import("Number-Theory")
| Number-Theory.thue-morse?(n) |
→ |
boolean |
Description
Checks if a number is part of the Thue-Morse sequence.
Examples
>
let { thue-morse? } = import("Number-Theory");
thue-morse?(1)
true
>
let { thue-morse? } = import("Number-Theory");
thue-morse?(2)
false
let { tribonacci-seq } = import("Number-Theory")
| Number-Theory.tribonacci-seq(length) |
→ |
Array<integer> |
Description
Generates the tribonacci sequence up to a specified length.
Arguments
| length |
integer |
The length of the sequence to generate.
|
Examples
>
let { tribonacci-seq } = import("Number-Theory");
tribonacci-seq(1)
[0]
>
let { tribonacci-seq } = import("Number-Theory");
tribonacci-seq(2)
[0, 1]
>
let { tribonacci-seq } = import("Number-Theory");
tribonacci-seq(10)
[
0,
1,
1,
2,
4,
7,
13,
24,
44,
81
]
let { tribonacci-take-while } = import("Number-Theory")
| Number-Theory.tribonacci-take-while(takeWhile) |
→ |
Array<integer> |
Description
Generates the tribonacci sequence while a condition is met.
Arguments
| takeWhile |
function |
A function that takes an integer and an index and returns a boolean.
|
Examples
>
let { tribonacci-take-while } = import("Number-Theory");
tribonacci-take-while(-> $ < 100)
[
0,
1,
1,
2,
4,
7,
13,
24,
44,
81
]
let { tribonacci-nth } = import("Number-Theory")
| Number-Theory.tribonacci-nth(n) |
→ |
integer |
Description
Generates the nth term of the tribonacci sequence.
Arguments
| n |
integer |
The index of the term to generate.
|
Examples
>
let { tribonacci-nth } = import("Number-Theory");
tribonacci-nth(1)
0
>
let { tribonacci-nth } = import("Number-Theory");
tribonacci-nth(2)
1
>
let { tribonacci-nth } = import("Number-Theory");
tribonacci-nth(10)
81
let { tribonacci? } = import("Number-Theory")
| Number-Theory.tribonacci?(n) |
→ |
boolean |
Description
Determines if a number is in the tribonacci sequence.
Examples
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(0)
true
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(1)
true
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(2)
true
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(3)
false
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(4)
true
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(5)
false
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(6)
false
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(7)
true
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(8)
false
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(9)
false
>
let { tribonacci? } = import("Number-Theory");
tribonacci?(10)
false
let { count-combinations } = import("Number-Theory")
| Number-Theory.count-combinations(a, b) |
→ |
integer |
Description
Calculates the number of combinations of n items taken k at a time.
Examples
>
let { count-combinations } = import("Number-Theory");
count-combinations(5, 3)
10
>
let { count-combinations } = import("Number-Theory");
count-combinations(10, 2)
45
let { combinations } = import("Number-Theory")
| Number-Theory.combinations(set, n) |
→ |
Array<array> |
Description
Generates all possible combinations of a specified size from a collection.
Arguments
| set |
Array<array> |
The input collection to generate combinations from.
|
| n |
integer |
The size of each combination.
|
| a |
array |
| b |
integer |
Examples
>
let { combinations } = import("Number-Theory");
combinations([1, 2, 3], 2)
[ 1 2 ]
[ 1 3 ]
[ 2 3 ]
>
let { combinations } = import("Number-Theory");
combinations(["a", "b", "c"], 2)
[
[
"a",
"b"
],
[
"a",
"c"
],
[
"b",
"c"
]
]
>
let { combinations } = import("Number-Theory");
combinations([1, 2, 3], 0)
[
[]
]
>
let { combinations } = import("Number-Theory");
combinations([1, 2, 3], 1)
[ 1 ]
[ 2 ]
[ 3 ]
>
let { combinations } = import("Number-Theory");
combinations([1, 2, 3], 3)
[ 1 2 3 ]
let { count-derangements } = import("Number-Theory")
| Number-Theory.count-derangements(n) |
→ |
integer |
Description
Calculates the number of derangements (permutations where no element appears in its original position) of n items.
Arguments
| n |
integer |
The total number of items.
|
Examples
>
let { count-derangements } = import("Number-Theory");
count-derangements(4)
9
>
let { count-derangements } = import("Number-Theory");
count-derangements(5)
44
let { derangements } = import("Number-Theory")
| Number-Theory.derangements(set) |
→ |
Array<array> |
Description
Generates all derangements (permutations where no element appears in its original position) of a set.
Arguments
| set |
Array<array> |
The input collection to generate derangements from.
|
Examples
>
let { derangements } = import("Number-Theory");
derangements([1, 2, 3, 4])
[ 2 1 4 3 ]
[ 2 3 4 1 ]
[ 2 4 1 3 ]
[ 3 1 4 2 ]
[ 3 4 1 2 ]
[ 3 4 2 1 ]
[ 4 1 2 3 ]
[ 4 3 1 2 ]
[ 4 3 2 1 ]
>
let { derangements } = import("Number-Theory");
derangements(["a", "b", "c"])
[
[
"b",
"c",
"a"
],
[
"c",
"a",
"b"
]
]
let { divisors } = import("Number-Theory")
| Number-Theory.divisors(n) |
→ |
Array<integer> |
Description
Returns the divisors of a number.
Arguments
| n |
integer |
The number to find divisors for.
|
Examples
>
let { divisors } = import("Number-Theory");
divisors(12)
[1, 2, 3, 4, 6, 12]
>
let { divisors } = import("Number-Theory");
divisors(100)
[
1,
2,
4,
5,
10,
20,
25,
50,
100
]
>
let { divisors } = import("Number-Theory");
divisors(37)
[1, 37]
let { count-divisors } = import("Number-Theory")
| Number-Theory.count-divisors(n) |
→ |
integer |
Description
Returns the number of divisors of a number.
Arguments
| n |
integer |
The number to count divisors for.
|
Examples
>
let { count-divisors } = import("Number-Theory");
count-divisors(12)
6
>
let { count-divisors } = import("Number-Theory");
count-divisors(100)
9
>
let { count-divisors } = import("Number-Theory");
count-divisors(37)
2
let { proper-divisors } = import("Number-Theory")
| Number-Theory.proper-divisors(n) |
→ |
Array<integer> |
Description
Returns the proper divisors of a number.
Arguments
| n |
integer |
The number to find proper divisors for.
|
Examples
>
let { proper-divisors } = import("Number-Theory");
proper-divisors(12)
[1, 2, 3, 4, 6]
>
let { proper-divisors } = import("Number-Theory");
proper-divisors(100)
[1, 2, 4, 5, 10, 20, 25, 50]
>
let { proper-divisors } = import("Number-Theory");
proper-divisors(37)
[1]
let { count-proper-divisors } = import("Number-Theory")
| Number-Theory.count-proper-divisors(n) |
→ |
integer |
Description
Returns the number of proper divisors of a number.
Arguments
| n |
integer |
The number to count proper divisors for.
|
Examples
>
let { count-proper-divisors } = import("Number-Theory");
count-proper-divisors(12)
5
>
let { count-proper-divisors } = import("Number-Theory");
count-proper-divisors(100)
8
>
let { count-proper-divisors } = import("Number-Theory");
count-proper-divisors(37)
1
let { factorial } = import("Number-Theory")
| Number-Theory.factorial(n) |
→ |
integer |
Description
Calculates the factorial of a number.
Arguments
| n |
integer |
The number to calculate the factorial for.
|
Examples
>
let { factorial } = import("Number-Theory");
factorial(5)
120
>
let { factorial } = import("Number-Theory");
factorial(0)
1
>
let { factorial } = import("Number-Theory");
factorial(10)
3628800
>
let { factorial } = import("Number-Theory");
factorial(20)
2432902008176640000
let { partitions } = import("Number-Theory")
| Number-Theory.partitions(n) |
→ |
Array<array> |
Description
Generates all partitions of a number.
Examples
>
let { partitions } = import("Number-Theory");
partitions(4)
[
[
4
],
[
3,
1
],
[
2,
2
],
[
2,
1,
1
],
[
1,
1,
1,
1
]
]
>
let { partitions } = import("Number-Theory");
partitions(8)
[
[
8
],
[
7,
1
],
[
6,
2
],
[
6,
1,
1
],
[
5,
3
],
[
5,
2,
1
],
[
5,
1,
1,
1
],
[
4,
4
],
[
4,
3,
1
],
[
4,
2,
2
],
[
4,
2,
1,
1
],
[
4,
1,
1,
1,
1
],
[
3,
3,
2
],
[
3,
3,
1,
1
],
[
3,
2,
2,
1
],
[
3,
2,
1,
1,
1
],
[
3,
1,
1,
1,
1,
1
],
[
2,
2,
2,
2
],
[
2,
2,
2,
1,
1
],
[
2,
2,
1,
1,
1,
1
],
[
2,
1,
1,
1,
1,
1,
1
],
[
1,
1,
1,
1,
1,
1,
1,
1
]
]
let { count-partitions } = import("Number-Theory")
| Number-Theory.count-partitions(n) |
→ |
integer |
Description
Returns the number of partitions of a number.
Arguments
| n |
integer |
The number to count partitions for.
|
Examples
>
let { count-partitions } = import("Number-Theory");
count-partitions(4)
5
>
let { count-partitions } = import("Number-Theory");
count-partitions(8)
22
>
let { count-partitions } = import("Number-Theory");
count-partitions(15)
176
let { permutations } = import("Number-Theory")
| Number-Theory.permutations(set) |
→ |
Array<array> |
Description
Generates all permutations of a collection.
Arguments
| set |
Array<array> |
The input collection to generate permutations from.
|
Examples
>
let { permutations } = import("Number-Theory");
permutations([1, 2, 3])
[ 1 2 3 ]
[ 1 3 2 ]
[ 2 1 3 ]
[ 2 3 1 ]
[ 3 1 2 ]
[ 3 2 1 ]
>
let { permutations } = import("Number-Theory");
permutations(["a", "b", "c"])
[
[
"a",
"b",
"c"
],
[
"a",
"c",
"b"
],
[
"b",
"a",
"c"
],
[
"b",
"c",
"a"
],
[
"c",
"a",
"b"
],
[
"c",
"b",
"a"
]
]
>
let { permutations } = import("Number-Theory");
permutations([1, 2, 3, 4])
[ 1 2 3 4 ]
[ 1 2 4 3 ]
[ 1 3 2 4 ]
[ 1 3 4 2 ]
[ 1 4 2 3 ]
[ 1 4 3 2 ]
[ 2 1 3 4 ]
[ 2 1 4 3 ]
[ 2 3 1 4 ]
[ 2 3 4 1 ]
[ 2 4 1 3 ]
[ 2 4 3 1 ]
[ 3 1 2 4 ]
[ 3 1 4 2 ]
[ 3 2 1 4 ]
[ 3 2 4 1 ]
[ 3 4 1 2 ]
[ 3 4 2 1 ]
[ 4 1 2 3 ]
[ 4 1 3 2 ]
[ 4 2 1 3 ]
[ 4 2 3 1 ]
[ 4 3 1 2 ]
[ 4 3 2 1 ]
>
let { permutations } = import("Number-Theory");
permutations([1, 2])
[ 1 2 ]
[ 2 1 ]
>
let { permutations } = import("Number-Theory");
permutations([1])
[ 1 ]
>
let { permutations } = import("Number-Theory");
permutations([])
[
[]
]
let { count-permutations } = import("Number-Theory")
| Number-Theory.count-permutations(a, b) |
→ |
integer |
Description
Returns the number of permutations of n items taken k at a time.
Examples
>
let { count-permutations } = import("Number-Theory");
count-permutations(5, 3)
60
>
let { count-permutations } = import("Number-Theory");
count-permutations(10, 2)
90
>
let { count-permutations } = import("Number-Theory");
count-permutations(10, 10)
3628800
>
let { count-permutations } = import("Number-Theory");
count-permutations(10, 0)
1
>
let { count-permutations } = import("Number-Theory");
count-permutations(10, 1)
10
let { power-set } = import("Number-Theory")
| Number-Theory.power-set(set) |
→ |
Array<array> |
Description
Generates the power set of a collection.
Arguments
| set |
Array<any> |
The input collection to generate the power set from.
|
Examples
>
let { power-set } = import("Number-Theory");
power-set(["a", "b", "c"])
[
[],
[
"a"
],
[
"b"
],
[
"a",
"b"
],
[
"c"
],
[
"a",
"c"
],
[
"b",
"c"
],
[
"a",
"b",
"c"
]
]
>
let { power-set } = import("Number-Theory");
power-set([1, 2])
[
[],
[
1
],
[
2
],
[
1,
2
]
]
>
let { power-set } = import("Number-Theory");
power-set([1])
[
[],
[
1
]
]
>
let { power-set } = import("Number-Theory");
power-set([])
[
[]
]
let { count-power-set } = import("Number-Theory")
| Number-Theory.count-power-set(n) |
→ |
integer |
Description
Returns the number of subsets of a set.
Examples
>
let { count-power-set } = import("Number-Theory");
count-power-set(3)
8
>
let { count-power-set } = import("Number-Theory");
count-power-set(5)
32
>
let { count-power-set } = import("Number-Theory");
count-power-set(10)
1024
let { prime-factors } = import("Number-Theory")
| Number-Theory.prime-factors(n) |
→ |
Array<integer> |
Description
Returns the prime factors of a number.
Examples
>
let { prime-factors } = import("Number-Theory");
prime-factors(12)
[2, 2, 3]
>
let { prime-factors } = import("Number-Theory");
prime-factors(100)
[2, 2, 5, 5]
>
let { prime-factors } = import("Number-Theory");
prime-factors(37)
[37]
let { count-prime-factors } = import("Number-Theory")
| Number-Theory.count-prime-factors(n) |
→ |
integer |
Description
Returns the number of prime factors of a number.
Arguments
| n |
integer |
The number to count prime factors for.
|
Examples
>
let { count-prime-factors } = import("Number-Theory");
count-prime-factors(12)
3
>
let { count-prime-factors } = import("Number-Theory");
count-prime-factors(100)
4
>
let { count-prime-factors } = import("Number-Theory");
count-prime-factors(37)
1
let { distinct-prime-factors } = import("Number-Theory")
| Number-Theory.distinct-prime-factors(n) |
→ |
Array<integer> |
Description
Returns the distinct prime factors of a number.
Arguments
| n |
integer |
The number to find distinct prime factors for.
|
Examples
>
let { distinct-prime-factors } = import("Number-Theory");
distinct-prime-factors(12)
[2, 3]
>
let { distinct-prime-factors } = import("Number-Theory");
distinct-prime-factors(100)
[2, 5]
>
let { distinct-prime-factors } = import("Number-Theory");
distinct-prime-factors(37)
[37]
let { count-distinct-prime-factors } = import("Number-Theory")
| Number-Theory.count-distinct-prime-factors(n) |
→ |
integer |
Description
Returns the number of distinct prime factors of a number.
Arguments
| n |
integer |
The number to count distinct prime factors for.
|
Examples
>
let { count-distinct-prime-factors } = import("Number-Theory");
count-distinct-prime-factors(12)
2
>
let { count-distinct-prime-factors } = import("Number-Theory");
count-distinct-prime-factors(100)
2
>
let { count-distinct-prime-factors } = import("Number-Theory");
count-distinct-prime-factors(37)
1
let { coprime? } = import("Number-Theory")
| Number-Theory.coprime?(a, b) |
→ |
boolean |
Description
Checks if two numbers are coprime (i.e., their GCD is 1).
Examples
>
let { coprime? } = import("Number-Theory");
coprime?(12, 8)
false
>
let { coprime? } = import("Number-Theory");
coprime?(12, 5)
true
>
let { coprime? } = import("Number-Theory");
coprime?(37, 1)
true
>
let { coprime? } = import("Number-Theory");
coprime?(0, 0)
false
>
let { coprime? } = import("Number-Theory");
coprime?(0, 5)
false
>
let { coprime? } = import("Number-Theory");
coprime?(5, 0)
false
>
let { coprime? } = import("Number-Theory");
coprime?(1, 0)
true
>
let { coprime? } = import("Number-Theory");
coprime?(0, 1)
true
>
let { coprime? } = import("Number-Theory");
coprime?(1, 1)
true
>
let { coprime? } = import("Number-Theory");
coprime?(2, 3)
true
let { divisible-by? } = import("Number-Theory")
| Number-Theory.divisible-by?(a, b) |
→ |
boolean |
Description
Checks if a number is divisible by another number.
Examples
>
let { divisible-by? } = import("Number-Theory");
divisible-by?(12, 4)
true
>
let { divisible-by? } = import("Number-Theory");
divisible-by?(12, 5)
false
>
let { divisible-by? } = import("Number-Theory");
divisible-by?(37, 1)
true
>
let { divisible-by? } = import("Number-Theory");
divisible-by?(0, 0)
false
>
let { divisible-by? } = import("Number-Theory");
divisible-by?(0, 5)
true
>
let { divisible-by? } = import("Number-Theory");
divisible-by?(5, 0)
false
let { gcd } = import("Number-Theory")
Description
Calculates the greatest common divisor (GCD) of two numbers.
Examples
>
let { gcd } = import("Number-Theory");
gcd(100, 25)
25
>
let { gcd } = import("Number-Theory");
gcd(37, 1)
1
>
let { gcd } = import("Number-Theory");
gcd(0, 0)
0
>
let { gcd } = import("Number-Theory");
gcd(0, 5)
5
>
let { gcd } = import("Number-Theory");
gcd(5, 0)
5
let { lcm } = import("Number-Theory")
Description
Calculates the least common multiple (LCM) of two numbers.
Examples
>
let { lcm } = import("Number-Theory");
lcm(100, 25)
100
>
let { lcm } = import("Number-Theory");
lcm(37, 1)
37
>
let { lcm } = import("Number-Theory");
lcm(0, 5)
0
>
let { lcm } = import("Number-Theory");
lcm(5, 0)
0
let { multinomial } = import("Number-Theory")
| Number-Theory.multinomial(...args) |
→ |
integer |
Description
Calculates the multinomial coefficient from of a list of numbers representing the sizes of each group.
Arguments
| args |
Array<integer> |
The numbers representing the sizes of each group.
|
Examples
>
let { multinomial } = import("Number-Theory");
multinomial(5, 2, 3)
2520
>
let { multinomial } = import("Number-Theory");
multinomial(10, 2, 3, 5)
465585120
let { amicable? } = import("Number-Theory")
| Number-Theory.amicable?(a, b) |
→ |
boolean |
Description
Checks if two numbers are amicable (i.e., the sum of the proper divisors of each number equals the other number).
Examples
>
let { amicable? } = import("Number-Theory");
amicable?(220, 284)
true
>
let { amicable? } = import("Number-Theory");
amicable?(1184, 1210)
true
>
let { amicable? } = import("Number-Theory");
amicable?(2620, 2924)
true
>
let { amicable? } = import("Number-Theory");
amicable?(5020, 5564)
true
>
let { amicable? } = import("Number-Theory");
amicable?(6232, 6368)
true
let { euler-totient } = import("Number-Theory")
| Number-Theory.euler-totient(n) |
→ |
integer |
Description
Calculates the Euler's totient function (φ(n)) of a number, which counts the integers up to n that are coprime to n.
Arguments
| n |
integer |
The number to calculate the totient for.
|
Examples
>
let { euler-totient } = import("Number-Theory");
euler-totient(1)
1
>
let { euler-totient } = import("Number-Theory");
euler-totient(2)
1
>
let { euler-totient } = import("Number-Theory");
euler-totient(10)
4
>
let { euler-totient } = import("Number-Theory");
euler-totient(20)
8
let { mobius } = import("Number-Theory")
Description
Calculates the Möbius function (μ(n)) of a number, which is used in number theory.
Arguments
| n |
integer |
The number to calculate the Möbius function for.
|
Examples
>
let { mobius } = import("Number-Theory");
mobius(1)
1
>
let { mobius } = import("Number-Theory");
mobius(2)
-1
>
let { mobius } = import("Number-Theory");
mobius(3)
-1
>
let { mobius } = import("Number-Theory");
mobius(4)
0
>
let { mobius } = import("Number-Theory");
mobius(6)
1
>
let { mobius } = import("Number-Theory");
mobius(12)
0
>
let { mobius } = import("Number-Theory");
mobius(30)
-1
let { mertens } = import("Number-Theory")
Description
Calculates the Mertens function (M(n)) of a number, which is the sum of the Möbius function up to n.
Arguments
| n |
integer |
The number to calculate the Mertens function for.
|
Examples
>
let { mobius } = import("Number-Theory");
mobius(1)
1
>
let { mobius } = import("Number-Theory");
mobius(2)
-1
>
let { mobius } = import("Number-Theory");
mobius(3)
-1
>
let { mobius } = import("Number-Theory");
mobius(4)
0
>
let { mobius } = import("Number-Theory");
mobius(6)
1
>
let { mobius } = import("Number-Theory");
mobius(12)
0
>
let { mobius } = import("Number-Theory");
mobius(30)
-1
let { sigma } = import("Number-Theory")
Description
Calculates the sum of divisors function (σ(n)) of a number, which is the sum of all positive divisors of n.
Arguments
| n |
integer |
The number to calculate the sum of divisors for.
|
Examples
>
let { sigma } = import("Number-Theory");
sigma(1)
1
>
let { sigma } = import("Number-Theory");
sigma(2)
3
>
let { sigma } = import("Number-Theory");
sigma(3)
4
>
let { sigma } = import("Number-Theory");
sigma(4)
7
>
let { sigma } = import("Number-Theory");
sigma(6)
12
>
let { sigma } = import("Number-Theory");
sigma(12)
28
>
let { sigma } = import("Number-Theory");
sigma(30)
72
let { carmichael-lambda } = import("Number-Theory")
| Number-Theory.carmichael-lambda(n) |
→ |
integer |
Description
Calculates the Carmichael function (λ(n)) of a number, which is the smallest positive integer m such that a^m ≡ 1 (mod n) for all integers a coprime to n.
Arguments
| n |
integer |
The number to calculate the Carmichael function for.
|
Examples
>
let { carmichael-lambda } = import("Number-Theory");
carmichael-lambda(1)
1
>
let { carmichael-lambda } = import("Number-Theory");
carmichael-lambda(2)
1
>
let { carmichael-lambda } = import("Number-Theory");
carmichael-lambda(3)
2
>
let { carmichael-lambda } = import("Number-Theory");
carmichael-lambda(4)
2
>
let { carmichael-lambda } = import("Number-Theory");
carmichael-lambda(6)
2
>
let { carmichael-lambda } = import("Number-Theory");
carmichael-lambda(12)
2
>
let { carmichael-lambda } = import("Number-Theory");
carmichael-lambda(30)
4
let { cartesian-product } = import("Number-Theory")
| Number-Theory.cartesian-product(sets) |
→ |
Array<array> |
Description
Calculates the Cartesian product of two or more sets.
Arguments
| sets |
Array<array> |
The input collections to calculate the Cartesian product from.
|
| a |
array |
| b |
array |
Examples
>
let { cartesian-product } = import("Number-Theory");
cartesian-product([1, 2], ["a", "b"])
[
[
1,
"a"
],
[
1,
"b"
],
[
2,
"a"
],
[
2,
"b"
]
]
>
let { cartesian-product } = import("Number-Theory");
cartesian-product([1, 2], ["a", "b"], [true, false])
[
[
1,
"a",
true
],
[
1,
"a",
false
],
[
1,
"b",
true
],
[
1,
"b",
false
],
[
2,
"a",
true
],
[
2,
"a",
false
],
[
2,
"b",
true
],
[
2,
"b",
false
]
]
>
let { cartesian-product } = import("Number-Theory");
cartesian-product([1, 2, 3], ["x", "y", "z"])
[
[
1,
"x"
],
[
1,
"y"
],
[
1,
"z"
],
[
2,
"x"
],
[
2,
"y"
],
[
2,
"z"
],
[
3,
"x"
],
[
3,
"y"
],
[
3,
"z"
]
]
let { perfect-power } = import("Number-Theory")
| Number-Theory.perfect-power(n) |
→ |
Array<array> |
Description
Returns a tuple of the base and exponent if the number is a perfect power, otherwise returns null.
Examples
>
let { perfect-power } = import("Number-Theory");
perfect-power(1)
[1, 2]
>
let { perfect-power } = import("Number-Theory");
perfect-power(2)
null
>
let { perfect-power } = import("Number-Theory");
perfect-power(4)
[2, 2]
>
let { perfect-power } = import("Number-Theory");
perfect-power(8)
[2, 3]
>
let { perfect-power } = import("Number-Theory");
perfect-power(9)
[3, 2]
>
let { perfect-power } = import("Number-Theory");
perfect-power(16)
[4, 2]
>
let { perfect-power } = import("Number-Theory");
perfect-power(19)
null
let { mod-exp } = import("Number-Theory")
| Number-Theory.mod-exp(base, exponent, modulus) |
→ |
integer |
Description
Calculates the modular exponentiation of a base raised to an exponent modulo a modulus.
Examples
>
let { mod-exp } = import("Number-Theory");
mod-exp(2, 3, 5)
3
>
let { mod-exp } = import("Number-Theory");
mod-exp(3, 4, 7)
4
>
let { mod-exp } = import("Number-Theory");
mod-exp(5, 6, 11)
5
>
let { mod-exp } = import("Number-Theory");
mod-exp(7, 8, 13)
3
let { mod-inv } = import("Number-Theory")
| Number-Theory.mod-inv(a, ) |
→ |
integer |
Description
Calculates the modular multiplicative inverse of a number modulo another number.
Examples
>
let { mod-inv } = import("Number-Theory");
mod-inv(3, 11)
4
>
let { mod-inv } = import("Number-Theory");
mod-inv(10, 17)
12
>
let { mod-inv } = import("Number-Theory");
mod-inv(5, 13)
8
>
let { mod-inv } = import("Number-Theory");
mod-inv(7, 19)
11
let { extended-gcd } = import("Number-Theory")
| Number-Theory.extended-gcd(a, b) |
→ |
Array<integer> |
Description
Calculates the extended greatest common divisor (GCD) of two numbers, returning the GCD and the coefficients of Bézout's identity.
Examples
>
let { extended-gcd } = import("Number-Theory");
extended-gcd(30, 12)
[6, 1, -2]
>
let { extended-gcd } = import("Number-Theory");
extended-gcd(56, 98)
[14, 2, -1]
>
let { extended-gcd } = import("Number-Theory");
extended-gcd(101, 10)
[1, 1, -10]
>
let { extended-gcd } = import("Number-Theory");
extended-gcd(17, 13)
[1, -3, 4]
let { chinese-remainder } = import("Number-Theory")
| Number-Theory.chinese-remainder(remainders, moduli) |
→ |
integer |
Description
Solves a system of simultaneous congruences using the Chinese Remainder Theorem.
Arguments
| remainders |
Array<integer> |
The remainders of the congruences.
|
| moduli |
Array<integer> |
The moduli of the congruences.
|
| a |
array |
| b |
array |
Examples
>
let { chinese-remainder } = import("Number-Theory");
chinese-remainder([2, 3], [3, 5])
8
>
let { chinese-remainder } = import("Number-Theory");
chinese-remainder([1, 2], [3, 4])
10
>
let { chinese-remainder } = import("Number-Theory");
chinese-remainder([0, 1], [2, 3])
4
>
let { chinese-remainder } = import("Number-Theory");
chinese-remainder([1, 2, 3], [4, 5, 7])
17
let { stirling-first } = import("Number-Theory")
| Number-Theory.stirling-first(a, b) |
→ |
integer |
Description
Calculates the Stirling numbers of the first kind, which count the number of permutations of n elements with k cycles.
Examples
>
let { stirling-first } = import("Number-Theory");
stirling-first(5, 2)
50
>
let { stirling-first } = import("Number-Theory");
stirling-first(4, 3)
6
>
let { stirling-first } = import("Number-Theory");
stirling-first(6, 1)
120
>
let { stirling-first } = import("Number-Theory");
stirling-first(7, 4)
735
>
let { stirling-first } = import("Number-Theory");
stirling-first(8, 5)
1960
let { stirling-second } = import("Number-Theory")
| Number-Theory.stirling-second(a, b) |
→ |
integer |
Description
Calculates the Stirling numbers of the second kind, which count the number of ways to partition n elements into k non-empty subsets.
Examples
>
let { stirling-second } = import("Number-Theory");
stirling-second(5, 2)
15
>
let { stirling-second } = import("Number-Theory");
stirling-second(4, 3)
6
>
let { stirling-second } = import("Number-Theory");
stirling-second(6, 1)
1
>
let { stirling-second } = import("Number-Theory");
stirling-second(7, 4)
350
>
let { stirling-second } = import("Number-Theory");
stirling-second(8, 5)
1050
let { every? } = import("Grid")
Description
Checks if all elements in a grid satisfy a predicate. Returns true only if the predicate returns true for every element in the grid.
Examples
>
// Using "as" alias because "every?" shadows a builtin function
let { every? as grid-every? } = import("Grid");
grid-every?([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], string?)
false
>
// Using "as" alias because "every?" shadows a builtin function
let { every? as grid-every? } = import("Grid");
grid-every?([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
], string?)
true
>
// Using "as" alias because "every?" shadows a builtin function
let { every? as grid-every? } = import("Grid");
grid-every?([
[1, 2],
[3, 4],
], string?)
false
let { some? } = import("Grid")
Description
Checks if any element in a grid satisfies a predicate. Returns true if the predicate returns true for at least one element in the grid.
Examples
>
let { some? } = import("Grid");
some?([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], string?)
true
>
let { some? } = import("Grid");
some?([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
], string?)
true
>
let { some? } = import("Grid");
some?([
[1, 2],
[3, 4],
], string?)
false
let { every-row? } = import("Grid")
Description
Checks if all rows in a grid satisfy a predicate. Returns true only if the predicate returns true for every row in the grid.
Examples
>
let { every-row? } = import("Grid");
every-row?([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], -> string?($[0]))
true
>
let { every-row? } = import("Grid");
every-row?([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
], -> string?($[0]))
true
>
let { every-row? } = import("Grid");
every-row?([
[1, 2],
[3, 4],
], -> string?($[0]))
false
let { some-row? } = import("Grid")
Description
Checks if any row in a grid satisfies a predicate. Returns true if the predicate returns true for at least one row in the grid.
Examples
>
let { some-row? } = import("Grid");
some-row?([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], -> $ contains? "Albert")
true
>
let { some-row? } = import("Grid");
some-row?([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
], -> $ contains? "Albert")
true
>
let { some-row? } = import("Grid");
some-row?([
[1, 2],
[3, 4],
], -> $ contains? "Albert")
false
let { every-col? } = import("Grid")
Description
Checks if all columns in a grid satisfy a predicate. Returns true only if the predicate returns true for every column in the grid.
Examples
>
let { every-col? } = import("Grid");
every-col?([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], -> string?($[0]))
false
>
let { every-col? } = import("Grid");
every-col?([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
], -> string?($[0]))
true
>
let { every-col? } = import("Grid");
every-col?([
[1, 2],
[3, 4],
], -> string?($[0]))
false
let { some-col? } = import("Grid")
Description
Checks if any column in a grid satisfies a predicate. Returns true if the predicate returns true for at least one column in the grid.
Examples
>
let { some-col? } = import("Grid");
some-col?([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], -> $ contains? "Albert")
true
>
let { some-col? } = import("Grid");
some-col?([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
], -> $ contains? "Albert")
true
>
let { some-col? } = import("Grid");
some-col?([
[1, 2],
[3, 4],
], -> $ contains? "Albert")
false
let { row } = import("Grid")
Description
Returns the row at index a in the grid b.
Examples
>
let { row } = import("Grid");
row([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 0)
[
"Albert",
"father",
10
]
>
let { row } = import("Grid");
row([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 1)
[
"Nina",
"mother",
20
]
>
let { row } = import("Grid");
row([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 2)
[
"Kian",
"son",
30
]
let { col } = import("Grid")
Description
Returns the column at index a in the grid b.
Examples
>
let { col } = import("Grid");
col([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 0)
[
"Albert",
"Nina",
"Kian"
]
>
let { col } = import("Grid");
col([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 1)
[
"father",
"mother",
"son"
]
>
let { col } = import("Grid");
col([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 2)
[10, 20, 30]
let { shape } = import("Grid")
Description
Returns the shape of the grid g as a vector of two numbers, where the first number is the number of rows and the second number is the number of columns.
Arguments
| g |
grid |
The grid to get the shape of.
|
Examples
>
let { shape } = import("Grid");
shape([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
])
[3, 3]
>
let { shape } = import("Grid");
shape([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
])
[3, 2]
>
let { shape } = import("Grid");
shape([
[1, 2],
[3, 4],
])
[2, 2]
let { fill } = import("Grid")
| Grid.fill(rows, cols, value) |
→ |
grid |
Description
Creates a grid of the specified size, filled with the specified value.
Arguments
| rows |
integer |
The number of rows in the grid.
|
| cols |
integer |
The number of columns in the grid.
|
| value |
any |
The value to fill the grid with.
|
Examples
>
let { fill } = import("Grid");
fill(2, 3, 0)
[ 0 0 0 ]
[ 0 0 0 ]
>
let { fill } = import("Grid");
fill(2, 3, "x")
[
[
"x",
"x",
"x"
],
[
"x",
"x",
"x"
]
]
let { generate } = import("Grid")
| Grid.generate(rows, cols, fn) |
→ |
grid |
Description
Generates a grid of the specified size, where each element is generated by the provided function.
Arguments
| rows |
number |
The number of rows in the grid.
|
| cols |
number |
The number of columns in the grid.
|
| fn |
function |
The function to generate the grid. It takes two arguments: the row index and the column index.
|
Examples
>
let { generate } = import("Grid");
generate(3, 3, (i, j) -> i + j)
[ 0 1 2 ]
[ 1 2 3 ]
[ 2 3 4 ]
let { reshape } = import("Grid")
| Grid.reshape(a, b) |
→ |
grid |
Description
Reshapes the grid a into a new grid with the specified number of rows b. The number of columns is automatically calculated based on the total number of elements in the grid.
Examples
>
let { reshape } = import("Grid");
reshape([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
], 2)
[
[
"Albert",
"father",
"Nina"
],
[
"mother",
"Kian",
"son"
]
]
let { transpose } = import("Grid")
Description
Transposes the grid g, swapping its rows and columns.
Arguments
| g |
grid |
The grid to transpose.
|
Examples
>
let { transpose } = import("Grid");
transpose([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
])
[
[
"Albert",
"Nina",
"Kian"
],
[
"father",
"mother",
"son"
],
[
10,
20,
30
]
]
>
let { transpose } = import("Grid");
transpose([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
])
[
[
"Albert",
"Nina",
"Kian"
],
[
"father",
"mother",
"son"
]
]
>
let { transpose } = import("Grid");
transpose([
[1, 2],
[3, 4],
])
[ 1 3 ]
[ 2 4 ]
let { flip-h } = import("Grid")
Description
Flips the grid g horizontally.
Arguments
| g |
grid |
The grid to flip horizontally.
|
Examples
>
let { flip-h } = import("Grid");
flip-h([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
])
[
[
10,
"father",
"Albert"
],
[
20,
"mother",
"Nina"
],
[
30,
"son",
"Kian"
]
]
>
let { flip-h } = import("Grid");
flip-h([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
])
[
[
"father",
"Albert"
],
[
"mother",
"Nina"
],
[
"son",
"Kian"
]
]
>
let { flip-h } = import("Grid");
flip-h([
[1, 2],
[3, 4],
])
[ 2 1 ]
[ 4 3 ]
let { flip-v } = import("Grid")
Description
Flips the grid g vertically.
Arguments
| g |
grid |
The grid to flip vertically.
|
Examples
>
let { flip-v } = import("Grid");
flip-v([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
])
[
[
"Kian",
"son",
30
],
[
"Nina",
"mother",
20
],
[
"Albert",
"father",
10
]
]
>
let { flip-v } = import("Grid");
flip-v([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
])
[
[
"Kian",
"son"
],
[
"Nina",
"mother"
],
[
"Albert",
"father"
]
]
>
let { flip-v } = import("Grid");
flip-v([
[1, 2],
[3, 4],
])
[ 3 4 ]
[ 1 2 ]
let { rotate } = import("Grid")
Description
Rotates the grid g by the specified angle. The angle is given in terms of 90-degree rotations. Positive values rotate the grid clockwise, while negative values rotate it counterclockwise.
Examples
>
let { rotate } = import("Grid");
rotate([
[1, 2],
[3, 4],
], 1)
[ 3 1 ]
[ 4 2 ]
>
let { rotate } = import("Grid");
rotate([
[1, 2],
[3, 4],
], 2)
[ 4 3 ]
[ 2 1 ]
>
let { rotate } = import("Grid");
rotate([
[1, 2],
[3, 4],
], 3)
[ 2 4 ]
[ 1 3 ]
>
let { rotate } = import("Grid");
rotate([
[1, 2],
[3, 4],
], 4)
[ 1 2 ]
[ 3 4 ]
>
let { rotate } = import("Grid");
rotate([
[1, 2],
[3, 4],
], -1)
[ 2 4 ]
[ 1 3 ]
>
let { rotate } = import("Grid");
rotate([
[1, 2],
[3, 4],
], -2)
[ 4 3 ]
[ 2 1 ]
>
let { rotate } = import("Grid");
rotate([
[1, 2],
[3, 4],
], -3)
[ 3 1 ]
[ 4 2 ]
let { reverse-rows } = import("Grid")
| Grid.reverse-rows(g) |
→ |
grid |
Description
Reverses the order of rows in the grid g.
Arguments
| g |
grid |
The grid to reverse rows.
|
Examples
>
let { reverse-rows } = import("Grid");
reverse-rows([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
])
[
[
"Kian",
"son",
30
],
[
"Nina",
"mother",
20
],
[
"Albert",
"father",
10
]
]
>
let { reverse-rows } = import("Grid");
reverse-rows([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
])
[
[
"Kian",
"son"
],
[
"Nina",
"mother"
],
[
"Albert",
"father"
]
]
>
let { reverse-rows } = import("Grid");
reverse-rows([
[1, 2],
[3, 4],
])
[ 3 4 ]
[ 1 2 ]
let { reverse-cols } = import("Grid")
| Grid.reverse-cols(g) |
→ |
grid |
Description
Reverses the order of columns in the grid g.
Arguments
| g |
grid |
The grid to reverse columns.
|
Examples
>
let { reverse-cols } = import("Grid");
reverse-cols([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
])
[
[
10,
"father",
"Albert"
],
[
20,
"mother",
"Nina"
],
[
30,
"son",
"Kian"
]
]
>
let { reverse-cols } = import("Grid");
reverse-cols([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
])
[
[
"father",
"Albert"
],
[
"mother",
"Nina"
],
[
"son",
"Kian"
]
]
>
let { reverse-cols } = import("Grid");
reverse-cols([
[1, 2],
[3, 4],
])
[ 2 1 ]
[ 4 3 ]
let { slice } = import("Grid")
| Grid.slice(g, begin) |
→ |
grid |
| Grid.slice(g, begin, stop) |
→ |
grid |
Description
Slices the grid g from the starting index begin to the optional ending index stop. The slice is inclusive of the starting index and exclusive of the ending index.
Arguments
| g |
grid |
The grid to slice.
|
| begin |
vector |
The starting index of the slice as a vector of two numbers: [row, col].
|
| stop |
vector |
Optional ending index of the slice as a vector of two numbers: [row, col].
|
Examples
>
// Using "as" alias because "slice" shadows a builtin function
let { slice as grid-slice } = import("Grid");
grid-slice([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], [1, 1], [2, 2])
[ mother ]
>
// Using "as" alias because "slice" shadows a builtin function
let { slice as grid-slice } = import("Grid");
grid-slice([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], [1, 1])
[
[
"mother",
20
],
[
"son",
30
]
]
let { slice-rows } = import("Grid")
| Grid.slice-rows(g, begin) |
→ |
grid |
| Grid.slice-rows(g, begin, stop) |
→ |
grid |
Description
Slices rows of the grid g from the starting index begin to the optional ending index stop. The slice is inclusive of the starting index and exclusive of the ending index.
Arguments
| g |
grid |
The grid to slice.
|
| begin |
number |
The starting index of the slice.
|
| stop |
number |
Optional ending index of the slice.
|
Examples
>
let { slice-rows } = import("Grid");
slice-rows([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 1, 2)
[ Nina mother 20 ]
>
let { slice-rows } = import("Grid");
slice-rows([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 1)
[
[
"Nina",
"mother",
20
],
[
"Kian",
"son",
30
]
]
let { slice-cols } = import("Grid")
| Grid.slice-cols(g, begin) |
→ |
grid |
| Grid.slice-cols(g, begin, stop) |
→ |
grid |
Description
Slices columns of the grid g from the starting index begin to the optional ending index stop. The slice is inclusive of the starting index and exclusive of the ending index.
Arguments
| g |
grid |
The grid to slice.
|
| begin |
number |
The starting index of the slice.
|
| stop |
number |
Optional ending index of the slice.
|
Examples
>
let { slice-cols } = import("Grid");
slice-cols([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 1, 2)
[
[
"father"
],
[
"mother"
],
[
"son"
]
]
>
let { slice-cols } = import("Grid");
slice-cols([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 1)
[
[
"father",
10
],
[
"mother",
20
],
[
"son",
30
]
]
let { splice-rows } = import("Grid")
| Grid.splice-rows(g, begin, deleteCount) |
→ |
grid |
| Grid.splice-rows(g, begin, deleteCount, ...items) |
→ |
grid |
Description
Splices rows of the grid g starting from the index begin. Deletes deleteCount rows and inserts the specified items at that position.
Arguments
| g |
grid |
The grid to splice.
|
| begin |
number |
The starting index of the splice.
|
| deleteCount |
number |
The number of rows to delete.
|
| items |
Array<array> |
The rows to insert.
|
Examples
>
let { splice-rows } = import("Grid");
splice-rows([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 1, 2)
[ Albert father 10 ]
>
let { splice-rows } = import("Grid");
splice-rows([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 1, 1, ["Nazanin", "mother", 40])
[
[
"Albert",
"father",
10
],
[
"Nazanin",
"mother",
40
],
[
"Kian",
"son",
30
]
]
let { splice-cols } = import("Grid")
| Grid.splice-cols(g, begin, deleteCount) |
→ |
grid |
| Grid.splice-cols(g, begin, deleteCount, ...items) |
→ |
grid |
Description
Splices columns of the grid g starting from the index begin. Deletes deleteCount columns and inserts the specified items at that position.
Arguments
| g |
grid |
The grid to splice.
|
| begin |
number |
The starting index of the splice.
|
| deleteCount |
number |
The number of columns to delete.
|
| items |
Array<array> |
The columns to insert.
|
Examples
>
let { splice-cols } = import("Grid");
splice-cols([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 1, 2)
[
[
"Albert"
],
[
"Nina"
],
[
"Kian"
]
]
>
let { splice-cols } = import("Grid");
splice-cols([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], 1, 1, ["f", "m", "s"])
[
[
"Albert",
"f",
10
],
[
"Nina",
"m",
20
],
[
"Kian",
"s",
30
]
]
let { concat-rows } = import("Grid")
| Grid.concat-rows(a, b) |
→ |
grid |
Description
Concatenates two grids a and b by rows. The number of columns in both grids must be the same.
Examples
>
let { concat-rows } = import("Grid");
concat-rows([
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
], [
[1, 2],
[3, 4],
])
[
[
"Albert",
"father"
],
[
"Nina",
"mother"
],
[
"Kian",
"son"
],
[
1,
2
],
[
3,
4
]
]
let { concat-cols } = import("Grid")
| Grid.concat-cols(a, b) |
→ |
grid |
Description
Concatenates two grids a and b by columns. The number of rows in both grids must be the same.
Examples
>
let { concat-cols } = import("Grid");
concat-cols([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], [
["Albert", "father"],
["Nina", "mother"],
["Kian", "son"],
])
[
[
"Albert",
"father",
10,
"Albert",
"father"
],
[
"Nina",
"mother",
20,
"Nina",
"mother"
],
[
"Kian",
"son",
30,
"Kian",
"son"
]
]
let { map } = import("Grid")
Description
Maps a function a over each element of the grid b, returning a new grid with the results.
Examples
>
// Using "as" alias because "map" shadows a builtin function
let { map as grid-map } = import("Grid");
grid-map([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], str)
[
[
"Albert",
"father",
"10"
],
[
"Nina",
"mother",
"20"
],
[
"Kian",
"son",
"30"
]
]
let { mapi } = import("Grid")
Description
Maps a function a over each element of the grid b, passing the row and column index as additional arguments to the function.
Examples
>
// Using "as" alias because "mapi" shadows a builtin function
let { mapi as grid-mapi } = import("Grid");
grid-mapi([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], -> $1 ++ "(" ++ $2 ++ ", " ++ $3 ++ ")")
[
[
"Albert(0, 0)",
"father(0, 1)",
"10(0, 2)"
],
[
"Nina(1, 0)",
"mother(1, 1)",
"20(1, 2)"
],
[
"Kian(2, 0)",
"son(2, 1)",
"30(2, 2)"
]
]
let { reduce } = import("Grid")
| Grid.reduce(g, fn, initial-value) |
→ |
any |
Description
Reduces the grid a using the function b, returning a single value.
Arguments
| g |
grid |
The grid to reduce.
|
| fn |
function |
The function to reduce the grid. It takes two arguments: the accumulator and the current element.
|
| initial-value |
any |
The initial value for the accumulator.
|
Examples
>
// Using "as" alias because "reduce" shadows a builtin function
let { reduce as grid-reduce } = import("Grid");
grid-reduce([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], ++, "")
"Albertfather10Ninamother20Kianson30"
let { reducei } = import("Grid")
| Grid.reducei(g, fn, initial-value) |
→ |
any |
Description
Reduces the grid a using the function b, passing the row and column indices as additional arguments to the function.
Arguments
| g |
grid |
The grid to reduce.
|
| fn |
function |
The function to reduce the grid. It takes four arguments: the accumulator, the current element, the row index, and the column index.
|
| initial-value |
any |
The initial value for the accumulator.
|
Examples
>
// Using "as" alias because "reducei" shadows a builtin function
let { reducei as grid-reducei } = import("Grid");
grid-reducei([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], ++, "")
"Albert00father011002Nina10mother112012Kian20son213022"
let { push-rows } = import("Grid")
| Grid.push-rows(g, ...rows) |
→ |
grid |
Description
Pushes the specified rows into the grid g and returns the new grid.
Arguments
| g |
grid |
The grid to push rows into.
|
| rows |
Array<array> |
The rows to push into the grid.
|
Examples
>
let { push-rows } = import("Grid");
push-rows([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], ["Nazanin", "mother", 40])
[
[
"Albert",
"father",
10
],
[
"Nina",
"mother",
20
],
[
"Kian",
"son",
30
],
[
"Nazanin",
"mother",
40
]
]
let { unshift-rows } = import("Grid")
| Grid.unshift-rows(g, ...rows) |
→ |
grid |
Description
Unshifts the specified rows into the grid g and returns the new grid.
Arguments
| g |
grid |
The grid to unshift rows into.
|
| rows |
Array<array> |
The rows to unshift into the grid.
|
Examples
>
let { unshift-rows } = import("Grid");
unshift-rows([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], ["Nazanin", "mother", 40])
[
[
"Nazanin",
"mother",
40
],
[
"Albert",
"father",
10
],
[
"Nina",
"mother",
20
],
[
"Kian",
"son",
30
]
]
let { pop-row } = import("Grid")
Description
Pops the last row from the grid g and returns the new grid.
Arguments
| g |
grid |
The grid to pop a row from.
|
Examples
>
let { pop-row } = import("Grid");
pop-row([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
])
[
[
"Albert",
"father",
10
],
[
"Nina",
"mother",
20
]
]
let { shift-row } = import("Grid")
Description
Shifts the first row from the grid g and returns the new grid.
Arguments
| g |
grid |
The grid to shift a row from.
|
Examples
>
let { shift-row } = import("Grid");
shift-row([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
])
[
[
"Nina",
"mother",
20
],
[
"Kian",
"son",
30
]
]
let { push-cols } = import("Grid")
| Grid.push-cols(g, ...cols) |
→ |
grid |
Description
Pushes the specified columns into the grid g and returns the new grid.
Arguments
| g |
grid |
The grid to push columns into.
|
| cols |
Array<array> |
The columns to push into the grid.
|
Examples
>
let { push-cols } = import("Grid");
push-cols([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], ["f", "m", "s"])
[
[
"Albert",
"father",
10,
"f"
],
[
"Nina",
"mother",
20,
"m"
],
[
"Kian",
"son",
30,
"s"
]
]
let { unshift-cols } = import("Grid")
| Grid.unshift-cols(g, ...cols) |
→ |
grid |
Description
Unshifts the specified columns into the grid g and returns the new grid.
Arguments
| g |
grid |
The grid to unshift columns into.
|
| cols |
Array<array> |
The columns to unshift into the grid.
|
Examples
>
let { unshift-cols } = import("Grid");
unshift-cols([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
], ["f", "m", "s"])
[
[
"f",
"Albert",
"father",
10
],
[
"m",
"Nina",
"mother",
20
],
[
"s",
"Kian",
"son",
30
]
]
let { pop-col } = import("Grid")
Description
Pops the last column from the grid g and returns the new grid.
Arguments
| g |
grid |
The grid to pop a column from.
|
Examples
>
let { pop-col } = import("Grid");
pop-col([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
])
[
[
"Albert",
"father"
],
[
"Nina",
"mother"
],
[
"Kian",
"son"
]
]
let { shift-col } = import("Grid")
Description
Shifts the first column from the grid g and returns the new grid.
Arguments
| g |
grid |
The grid to shift a column from.
|
Examples
>
let { shift-col } = import("Grid");
shift-col([
["Albert", "father", 10],
["Nina", "mother", 20],
["Kian", "son", 30],
])
[
[
"father",
10
],
[
"mother",
20
],
[
"son",
30
]
]
let { from-array } = import("Grid")
| Grid.from-array(a, b) |
→ |
grid |
Description
Creates a grid from a flat array with specified dimensions. The array is reshaped into the specified number of rows, and the number of columns is automatically calculated based on the total number of elements in the array.
Examples
>
let { from-array } = import("Grid");
from-array([1, 2, 3, 4], 2)
[ 1 2 ]
[ 3 4 ]
>
let { from-array } = import("Grid");
from-array([1, 2, 3, 4], 4)
[ 1 ]
[ 2 ]
[ 3 ]
[ 4 ]
let { random! } = import("Random")
Description
Returns a random number between 0 and 1.
Examples
>
let { random! } = import("Random"); random!()
0.724649596918931
let { random-int! } = import("Random")
Description
Returns a random integer between min and max (exclusive).
Examples
>
let { random-int! } = import("Random"); random-int!(0, 10)
1
>
let { random-int! } = import("Random"); random-int!(1, 100)
82
let { random-int-inclusive! } = import("Random")
| Random.random-int-inclusive!(a, b) |
→ |
integer |
Description
Returns a random integer between min and max (inclusive).
Examples
>
let { random-int-inclusive! } = import("Random"); random-int-inclusive!(0, 10)
7
let { random-float! } = import("Random")
| Random.random-float!(a, b) |
→ |
number |
Description
Returns a random float between min and max.
Examples
>
let { random-float! } = import("Random"); random-float!(0, 10)
2.57336692966055
>
let { random-float! } = import("Random"); random-float!(1, 100)
17.049504998001634
let { random-boolean! } = import("Random")
| Random.random-boolean!(prob) |
→ |
boolean |
Description
Returns a random boolean.
Arguments
| prob |
number |
The probability of returning true (between 0 and 1).
|
Examples
>
let { random-boolean! } = import("Random"); random-boolean!()
true
>
let { random-boolean! } = import("Random"); random-boolean!(0.99)
true
let { random-item! } = import("Random")
| Random.random-item!(a) |
→ |
any |
Description
Returns a random item from the array.
Arguments
| a |
array |
The array to sample from.
|
Examples
>
let { random-item! } = import("Random"); random-item!([1, 2, 3, 4, 5])
1
>
let { random-item! } = import("Random"); random-item!(["apple", "banana", "cherry"])
"cherry"
let { random-sample-unique! } = import("Random")
| Random.random-sample-unique!(a, b) |
→ |
array |
Description
Returns a random sample of n unique items from the array.
Arguments
| a |
array |
The array to sample from.
|
| b |
integer |
The number of items to sample.
|
Examples
>
let { random-sample-unique! } = import("Random"); random-sample-unique!([1, 2, 3, 4, 5], 3)
[5, 2, 1]
>
let { random-sample-unique! } = import("Random"); random-sample-unique!(["apple", "banana", "cherry"], 2)
[
"apple",
"cherry"
]
let { random-sample! } = import("Random")
| Random.random-sample!(a, b) |
→ |
array |
Description
Returns a random sample of n items from the array.
Arguments
| a |
array |
The array to sample from.
|
| b |
integer |
The number of items to sample.
|
Examples
>
let { random-sample! } = import("Random"); random-sample!([1, 2, 3, 4, 5], 3)
[5, 5, 4]
>
let { random-sample! } = import("Random"); random-sample!(["apple", "banana", "cherry"], 10)
[
"apple",
"apple",
"apple",
"apple",
"banana",
"apple",
"apple",
"banana",
"apple",
"apple"
]
let { shuffle! } = import("Random")
| Random.shuffle!(a) |
→ |
array |
Description
Returns a shuffled version of the array.
Arguments
| a |
array |
The array to shuffle.
|
Examples
>
let { shuffle! } = import("Random"); shuffle!([1, 2, 3, 4, 5])
[1, 4, 5, 2, 3]
>
let { shuffle! } = import("Random"); shuffle!(["apple", "banana", "cherry"])
[
"apple",
"banana",
"cherry"
]
let { random-normal! } = import("Random")
| Random.random-normal!(mean, stdDev) |
→ |
number |
Description
Returns a random number from a normal distribution with the given mean and standard deviation.
Arguments
| mean |
number |
The mean of the normal distribution.
|
| stdDev |
number |
The standard deviation of the normal distribution.
|
Examples
>
let { random-normal! } = import("Random"); random-normal!(0, 1)
0.38925484048946507
>
let { random-normal! } = import("Random"); random-normal!(5, 2)
10.109562581022221
let { random-exponential! } = import("Random")
| Random.random-exponential!(lambda) |
→ |
number |
Description
Returns a random number from an exponential distribution with the given rate parameter.
Arguments
| lambda |
number |
The rate parameter of the exponential distribution.
|
Examples
>
let { random-exponential! } = import("Random"); random-exponential!(1)
1.4877374860712662
>
let { random-exponential! } = import("Random"); random-exponential!(0.5)
0.16833790169340326
let { random-binomial! } = import("Random")
| Random.random-binomial!(n, p) |
→ |
integer |
Description
Returns a random number from a binomial distribution with the given number of trials and probability of success.
Arguments
| n |
integer |
The number of trials.
|
| p |
number |
The probability of success on each trial.
|
Examples
>
let { random-binomial! } = import("Random"); random-binomial!(10, 0.5)
5
>
let { random-binomial! } = import("Random"); random-binomial!(20, 0.3)
9
let { random-poisson! } = import("Random")
| Random.random-poisson!(lambda) |
→ |
integer |
Description
Returns a random number from a Poisson distribution with the given rate parameter.
Arguments
| lambda |
number |
The rate parameter of the Poisson distribution.
|
Examples
>
let { random-poisson! } = import("Random"); random-poisson!(1)
0
>
let { random-poisson! } = import("Random"); random-poisson!(5)
1
let { random-gamma! } = import("Random")
| Random.random-gamma!(shape, scale) |
→ |
number |
Description
Returns a random number from a gamma distribution with the given shape and scale parameters.
Arguments
| shape |
number |
The shape parameter of the gamma distribution.
|
| scale |
number |
The scale parameter of the gamma distribution.
|
Examples
>
let { random-gamma! } = import("Random"); random-gamma!(2, 2)
2.5155576700728783
>
let { random-gamma! } = import("Random"); random-gamma!(5, 1)
1.9613301027957826
let { random-pareto! } = import("Random")
| Random.random-pareto!(alpha) |
→ |
number |
Description
Returns a random number from a Pareto distribution with the given shape parameter.
Arguments
| alpha |
number |
The shape parameter of the Pareto distribution.
|
Examples
>
let { random-pareto! } = import("Random"); random-pareto!(1)
1.0665602640632295
>
let { random-pareto! } = import("Random"); random-pareto!(2)
1.580525471468094
let { uuid! } = import("Random")
Description
Returns a random UUID v4 (Universally Unique Identifier).
Examples
>
let { uuid! } = import("Random"); uuid!()
"071316e3-9d6e-4dde-a600-c259f924dfe4"
let { random-char! } = import("Random")
| Random.random-char!(charSet) |
→ |
string |
Description
Returns a random character from the given string.
Arguments
| charSet |
string |
The string to sample from.
|
Examples
>
let { random-char! } = import("Random"); random-char!("abcde")
"a"
>
let { random-char! } = import("Random"); random-char!("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
"R"
let { random-string! } = import("Random")
| Random.random-string!(length, charSet) |
→ |
string |
Description
Returns a random string of the given length from the given string.
Arguments
| length |
integer |
The length of the random string.
|
| charSet |
string |
The string to sample from.
|
Examples
>
let { random-string! } = import("Random"); random-string!(10, "abcde")
"dddceeaeac"
>
let { random-string! } = import("Random"); random-string!(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
"RFOFI"
let { random-id! } = import("Random")
| Random.random-id!(length) |
→ |
string |
Description
Returns a random ID of the given length.
Arguments
| length |
integer |
The length of the random ID.
|
Examples
>
let { random-id! } = import("Random"); random-id!(10)
"4PkKCJYVLs"
>
let { random-id! } = import("Random"); random-id!(5)
"68zEq"
let { random-color! } = import("Random")
| Random.random-color!() |
→ |
string |
Description
Returns a random color in hex format.
Examples
>
let { random-color! } = import("Random"); random-color!()
"#93916f"
| Assert.assert(value) |
→ |
any |
| Assert.assert(value, message) |
→ |
any |
Description
If value is falsy it throws AssertionError with message. If no message is provided, message is set to value.
Examples
>
let { assert } = import("Assert");
try assert(0, "Expected a positive value") catch (e) e.message end
"Expected a positive value"
| Assert.assert!=(a, b) |
→ |
null |
| Assert.assert!=(a, b, message) |
→ |
null |
Description
If a is the same as b it throws AssertionError.
Examples
>
let { assert!= } = import("Assert");
try assert!=(0, 0, "Expected different values") catch (e) e.message end
"Expected 0 not to deep equal 0. Expected different values"
>
let { assert!= } = import("Assert");
try assert!=(0, 0) catch (e) e.message end
"Expected 0 not to deep equal 0."
>
let { assert!= } = import("Assert");
try 0 assert!= 0 catch (e) e.message end
"Expected 0 not to deep equal 0."
>
let { assert!= } = import("Assert");
try assert!=(0, 1) catch (e) e.message end
null
| Assert.assert=(a, b) |
→ |
null |
| Assert.assert=(a, b, message) |
→ |
null |
Description
If a is not structural equal to b it throws AssertionError.
Examples
>
let { assert= } = import("Assert");
try assert=({ "a": 1 }, { "a": 2 }, "Expected equal values") catch (e) e.message end
"Expected {
"a": 1
} to deep equal {
"a": 2
}. Expected equal values"
>
let { assert= } = import("Assert");
try assert=({ "a": 1 }, { "a": 2 }) catch (e) e.message end
"Expected {
"a": 1
} to deep equal {
"a": 2
}."
>
let { assert= } = import("Assert");
try assert=({ "a": 1 }, { "a": 1 }) catch (e) e.message end
null
| Assert.assert-gt(a, b) |
→ |
null |
| Assert.assert-gt(a, b, message) |
→ |
null |
Description
If a is not greater than b it throws AssertionError.
Examples
>
let { assert-gt } = import("Assert");
try assert-gt(0, 1, "Expected greater value") catch (e) e.message end
"Expected 0 to be grater than 1. Expected greater value"
>
let { assert-gt } = import("Assert");
try assert-gt(0, 0) catch (e) e.message end
"Expected 0 to be grater than 0."
>
let { assert-gt } = import("Assert");
try assert-gt(1, 0) catch (e) e.message end
null
| Assert.assert-lt(a, b) |
→ |
null |
| Assert.assert-lt(a, b, message) |
→ |
null |
Description
If a is not less than b it throws AssertionError.
Examples
>
let { assert-lt } = import("Assert");
try assert-lt(1, 0, "Expected smaller value value") catch (e) e.message end
"Expected 1 to be less than 0. Expected smaller value value"
>
let { assert-lt } = import("Assert");
try assert-lt(1, 1) catch (e) e.message end
"Expected 1 to be less than 1."
>
let { assert-lt } = import("Assert");
try assert-lt(0, 1) catch (e) e.message end
null
| Assert.assert-gte(a, b) |
→ |
null |
| Assert.assert-gte(a, b, message) |
→ |
null |
Description
If a is less than b it throws AssertionError.
Examples
>
let { assert-gte } = import("Assert");
try assert-gte(0, 1, "Expected greater value") catch (e) e.message end
"Expected 0 to be grater than or equal to 1. Expected greater value"
>
let { assert-gte } = import("Assert");
try assert-gte(0, 1) catch (e) e.message end
"Expected 0 to be grater than or equal to 1."
>
let { assert-gte } = import("Assert");
try assert-gte(1, 1) catch (e) e.message end
null
| Assert.assert-lte(a, b) |
→ |
null |
| Assert.assert-lte(a, b, message) |
→ |
null |
Description
If a is grater than b it throws AssertionError.
Examples
>
let { assert-lte } = import("Assert");
try assert-lte(1, 0, "Expected smaller value value") catch (e) e.message end
"Expected 1 to be less than or equal to 0. Expected smaller value value"
>
let { assert-lte } = import("Assert");
try assert-lte(1, 0) catch (e) e.message end
"Expected 1 to be less than or equal to 0."
>
let { assert-lte } = import("Assert");
try assert-lte(1, 1) catch (e) e.message end
null
| Assert.assert-true(value) |
→ |
null |
| Assert.assert-true(value, message) |
→ |
null |
Description
If value is not true it throws AssertionError.
Examples
>
let { assert-true } = import("Assert");
try assert-true(false, "Expected true") catch (e) e.message end
"Expected false to be true. Expected true"
>
let { assert-true } = import("Assert");
try assert-true(false) catch (e) e.message end
"Expected false to be true."
>
let { assert-true } = import("Assert");
try assert-true(true) catch (e) e.message end
null
| Assert.assert-false(value) |
→ |
null |
| Assert.assert-false(value, message) |
→ |
null |
Description
If value is not false it throws AssertionError.
Examples
>
let { assert-false } = import("Assert");
try assert-false(true, "Expected false") catch (e) e.message end
"Expected true to be false. Expected false"
>
let { assert-false } = import("Assert");
try assert-false(true) catch (e) e.message end
"Expected true to be false."
>
let { assert-false } = import("Assert");
try assert-false(false) catch (e) e.message end
null
| Assert.assert-truthy(value) |
→ |
null |
| Assert.assert-truthy(value, message) |
→ |
null |
Description
If value is not truthy it throws AssertionError.
Examples
>
let { assert-truthy } = import("Assert");
try assert-truthy(false, "Expected truthy") catch (e) e.message end
"Expected false to be truthy. Expected truthy"
>
let { assert-truthy } = import("Assert");
try assert-truthy(false) catch (e) e.message end
"Expected false to be truthy."
>
let { assert-truthy } = import("Assert");
try assert-truthy(0) catch (e) e.message end
"Expected 0 to be truthy."
>
let { assert-truthy } = import("Assert");
try assert-truthy(null) catch (e) e.message end
"Expected null to be truthy."
>
let { assert-truthy } = import("Assert");
try assert-truthy("") catch (e) e.message end
"Expected to be truthy."
>
let { assert-truthy } = import("Assert");
try assert-truthy(true) catch (e) e.message end
null
>
let { assert-truthy } = import("Assert");
try assert-truthy(1) catch (e) e.message end
null
>
let { assert-truthy } = import("Assert");
try assert-truthy("x") catch (e) e.message end
null
>
let { assert-truthy } = import("Assert");
try assert-truthy([]) catch (e) e.message end
null
>
let { assert-truthy } = import("Assert");
try assert-truthy(nd) catch (e) e.message end
"Undefined symbol 'nd'."
| Assert.assert-falsy(value) |
→ |
null |
| Assert.assert-falsy(value, message) |
→ |
null |
Description
If value is not falsy it throws AssertionError.
Examples
>
let { assert-falsy } = import("Assert");
try assert-falsy(true, "Expected falsy") catch (e) e.message end
"Expected true to be falsy. Expected falsy"
>
let { assert-falsy } = import("Assert");
try assert-falsy("x") catch (e) e.message end
"Expected x to be falsy."
>
let { assert-falsy } = import("Assert");
try assert-falsy([]) catch (e) e.message end
"Expected to be falsy."
>
let { assert-falsy } = import("Assert");
try assert-falsy(nd) catch (e) e.message end
"Undefined symbol 'nd'."
>
let { assert-falsy } = import("Assert");
try assert-falsy(1) catch (e) e.message end
"Expected 1 to be falsy."
>
let { assert-falsy } = import("Assert");
try assert-falsy(false) catch (e) e.message end
null
>
let { assert-falsy } = import("Assert");
try assert-falsy(0) catch (e) e.message end
null
>
let { assert-falsy } = import("Assert");
try assert-falsy(null) catch (e) e.message end
null
>
let { assert-falsy } = import("Assert");
try assert-falsy("") catch (e) e.message end
null
| Assert.assert-null(value) |
→ |
null |
| Assert.assert-null(value, message) |
→ |
null |
Description
If value is not null it throws AssertionError.
Examples
>
let { assert-null } = import("Assert");
try assert-null(null) catch (e) e.message end
null
>
let { assert-null } = import("Assert");
try assert-null(true, "Expected null") catch (e) e.message end
"Expected true to be null. Expected null"
>
let { assert-null } = import("Assert");
try assert-null("x") catch (e) e.message end
"Expected x to be null."
>
let { assert-null } = import("Assert");
try assert-null([]) catch (e) e.message end
"Expected to be null."
>
let { assert-null } = import("Assert");
try assert-null(nd) catch (e) e.message end
"Undefined symbol 'nd'."
>
let { assert-null } = import("Assert");
try assert-null(1) catch (e) e.message end
"Expected 1 to be null."
>
let { assert-null } = import("Assert");
try assert-null(false) catch (e) e.message end
"Expected false to be null."
>
let { assert-null } = import("Assert");
try assert-null(0) catch (e) e.message end
"Expected 0 to be null."
>
let { assert-null } = import("Assert");
try assert-null("") catch (e) e.message end
"Expected to be null."
| Assert.assert-throws(fun) |
→ |
null |
| Assert.assert-throws(fun, message) |
→ |
null |
Description
If fun does not throw, it throws AssertionError.
Examples
>
let { assert-throws } = import("Assert");
assert-throws(-> throw("Error"))
null
>
let { assert-throws } = import("Assert");
try assert-throws(-> identity("Error")) catch (e) e.message end
"Expected function to throw."
| Assert.assert-throws-error(, error-message) |
→ |
null |
| Assert.assert-throws-error(, error-message, message) |
→ |
null |
Description
If fun does not throw error-message, it throws AssertionError.
Examples
>
let { assert-throws-error } = import("Assert");
try assert-throws-error(-> throw("Error"), "Error") catch (e) e.message end
null
>
let { assert-throws-error } = import("Assert");
try assert-throws-error(-> identity("Error"), "Error") catch (e) e.message end
"Expected function to throw "Error"."
| Assert.assert-not-throws(fun) |
→ |
null |
| Assert.assert-not-throws(fun, message) |
→ |
null |
Description
If fun throws, it throws AssertionError.
Examples
>
let { assert-not-throws } = import("Assert");
try assert-not-throws(-> identity("Error")) catch (e) e.message end
null
>
let { assert-not-throws } = import("Assert");
try assert-not-throws(-> throw("Error")) catch (e) e.message end
"Expected function not to throw."